From 5475f5e2116d47bf0319bf0264615c980ff5cdad Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 29 Sep 2022 13:20:11 -0500 Subject: [PATCH] refactor(gamm): improve error handling and messages when parsing pool assets (#2804) Closes: #XXX ## What is the purpose of the change The errors were non-descriptive, and, as a result, making the debugging experience more difficult. This refactor improves error messages. This is not state breaking because we still return error if any of the denoms are missing. Error messages do not affect state breaks ## Testing and Verifying This change is a trivial rework / code cleanup without any test coverage. ## Documentation and Release Note - Does this pull request introduce a new feature or user-facing behavior changes? no - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? yes - How is the feature or change documented? not applicable (cherry picked from commit f024498f1e8e0d2a1fe259cd9cc4223803fea0cd) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 17 +++++++++++++++++ x/gamm/pool-models/balancer/pool.go | 13 ++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0760c657a55..f78ee06a95a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +<<<<<<< HEAD +======= +## Unreleased + +### Features + +* [#2739](https://github.com/osmosis-labs/osmosis/pull/2739) Add pool type query + +### Bug fixes + +* [#2803](https://github.com/osmosis-labs/osmosis/pull/2803) Fix total pool liquidity CLI query. + +### Misc Improvements + +* [#2804](https://github.com/osmosis-labs/osmosis/pull/2804) Improve error handling and messages when parsing pool assets. + +>>>>>>> f024498f (refactor(gamm): improve error handling and messages when parsing pool assets (#2804)) ## v12.0.0 This release includes several cosmwasm-developer and appchain-ecosystem affecting upgrades: diff --git a/x/gamm/pool-models/balancer/pool.go b/x/gamm/pool-models/balancer/pool.go index b49b83451d9..c9315c81b0f 100644 --- a/x/gamm/pool-models/balancer/pool.go +++ b/x/gamm/pool-models/balancer/pool.go @@ -248,8 +248,12 @@ func (p Pool) parsePoolAssetsByDenoms(tokenADenom, tokenBDenom string) ( ) { Aasset, found1 := getPoolAssetByDenom(p.PoolAssets, tokenADenom) Basset, found2 := getPoolAssetByDenom(p.PoolAssets, tokenBDenom) - if !(found1 && found2) { - return Aasset, Basset, errors.New("one of the provided pool denoms does not exist in pool") + + if !found1 { + return PoolAsset{}, PoolAsset{}, fmt.Errorf("(%s) does not exist in the pool", tokenADenom) + } + if !found2 { + return PoolAsset{}, PoolAsset{}, fmt.Errorf("(%s) does not exist in the pool", tokenBDenom) } return Aasset, Basset, nil } @@ -261,7 +265,10 @@ func (p Pool) parsePoolAssets(tokensA sdk.Coins, tokenBDenom string) ( return tokenA, Aasset, Basset, errors.New("expected tokensB to be of length one") } Aasset, Basset, err = p.parsePoolAssetsByDenoms(tokensA[0].Denom, tokenBDenom) - return tokensA[0], Aasset, Basset, err + if err != nil { + return sdk.Coin{}, PoolAsset{}, PoolAsset{}, err + } + return tokensA[0], Aasset, Basset, nil } func (p Pool) parsePoolAssetsCoins(tokensA sdk.Coins, tokensB sdk.Coins) (