Skip to content

Commit

Permalink
refactor(gamm): improve error handling and messages when parsing pool…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
p0mvn authored Sep 29, 2022
1 parent 76a99c7 commit f024498
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### 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.

## v12.0.0

This release includes several cosmwasm-developer and appchain-ecosystem affecting upgrades:
Expand Down
13 changes: 10 additions & 3 deletions x/gamm/pool-models/balancer/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) (
Expand Down

0 comments on commit f024498

Please sign in to comment.