Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clean up chain error message handling #2759

Open
p0mvn opened this issue Jan 31, 2024 · 0 comments
Open

refactor: clean up chain error message handling #2759

p0mvn opened this issue Jan 31, 2024 · 0 comments

Comments

@p0mvn
Copy link
Member

p0mvn commented Jan 31, 2024

Context

To format chain error message, we do regex parsing:

const regexLegacySignatureVerificationFailed =
/^signature verification failed; please verify account number \(\d*\), sequence \((\d*)\) and chain-id \(.*\): unauthorized/;
const regexSignatureVerificationFailed =
/^account sequence mismatch, expected (\d*), got (\d*): incorrect account sequence/;
const regexFailedToExecuteMessageAt =
/^failed to execute message; message index: (\d+): (.+)/;
const regexCoinsOrDenoms = /(\d*)([a-zA-Z][a-zA-Z0-9/]{2,127})(,*)/g;
const regexSplitAmountAndDenomOfCoin = /(\d+)([a-zA-Z][a-zA-Z0-9/]{2,127})/;
const regexInvalidClPositionAmounts =
/failed to execute message; message index: (\d+): slippage bound: insufficient amount of token (\d+) created. Actual: \((\d+)\). Minimum estimated: \((\d+)\)/;
const regexFailedSwapSlippage =
/failed to execute message; message index: \d+: (.*?) token is lesser than min amount: calculated amount is lesser than min amount: invalid request/;

A cleaner approach would be to check SDK error codes like we do here:

if (tx.code === txTimeoutHeightReachedErrorCode) {
return "errors.txTimedOutError";
}

An example of an error code: https://github.com/cosmos/cosmos-sdk/blob/8f6a94cd1f9f1c6bf1ad83a751da86270db92e02/types/errors/errors.go#L129

We should refactor our error handling and formatting to be dependent on error codes as opposed to regex matching

Acceptance Criteria

  • Cleaned up errors
  • Error codes used
  • All tested
  • No error message is broken by the refactor
@p0mvn p0mvn changed the title refactore: clean up chain error message handling refactor: clean up chain error message handling Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant