Skip to content

Patch for fromMultibase syntax error on plain string inputs - #14

Merged
emmacasolin merged 1 commit into
masterfrom
frommultibase-patch
Feb 16, 2022
Merged

emmacasolin merged 1 commit into
masterfrom
frommultibase-patch

Conversation

@emmacasolin

@emmacasolin emmacasolin commented Feb 16, 2022 •

Copy link
Copy Markdown
Contributor

Description

The fromMultibase() utility was throwing a Syntax Error on plain string inputs, when it should instead have been returning undefined. The line this was coming from, codec.decode(), has now been warpped in a try-catch block in order to return undefined on this error, as is the expected behaviour.

Tasks

  1. Add a catch handler on codec.decode() for Syntax Errors
  2. Update utils tests to cover this case

Final checklist

  • Domain specific tests
  • Full tests
  • Updated inline-comment documentation
  • Lint fixed
  • Squash and rebased
  • Sanity check the final build

@emmacasolin
emmacasolin merged commit f2054bf into master Feb 16, 2022
@emmacasolin
emmacasolin deleted the frommultibase-patch branch February 16, 2022 03:41
Comment thread src/utils.ts
Comment on lines +169 to +177
let buffer: Uint8Array;
try {
buffer = codec.decode(idString);
} catch (e) {
if (e instanceof SyntaxError) {
return;
}
throw e;
}

@tegefaulkes tegefaulkes Feb 21, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still broken. Here is an example of a failing test.

  test('fromMultibase is throwing an error', async () => {
    expect(IdInternal.fromMultibase('zF4VfF3uRhSqgxTOOLONGxTRdVKauV9')).toBeUndefined();
    expect(IdInternal.fromMultibase('zFxTOOSHORTx9')).toBeUndefined();
  })

I think the problem is that it's throwing just a normal Error() with the message Non-base58btc character so it's not getting caught by the catch block and returning undefined.

Problem is that any base is valid for decoding and each one will have it's own error message. we may have to catch all errors here and return with undefined.

@CMCDragonkai , @emmacasolin

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have sworn it was SyntaxError.

Can you confirm if it is actually throwing Error?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I checked, yea it does do this.

Well then we just need to change it to:

} catch (e) {
  return;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emmacasolin can you clean this up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix is on the same branch but in a different PR here: #15

@emmacasolin
emmacasolin restored the frommultibase-patch branch February 21, 2022 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants