Repository navigation
Patch for fromMultibase syntax error on plain string inputs - #14
Conversation
| let buffer: Uint8Array; | ||
| try { | ||
| buffer = codec.decode(idString); | ||
| } catch (e) { | ||
| if (e instanceof SyntaxError) { | ||
| return; | ||
| } | ||
| throw e; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Could have sworn it was SyntaxError.
Can you confirm if it is actually throwing Error?
There was a problem hiding this comment.
Ok I checked, yea it does do this.
Well then we just need to change it to:
} catch (e) {
return;
}
There was a problem hiding this comment.
Fix is on the same branch but in a different PR here: #15
Description
The
fromMultibase()utility was throwing a Syntax Error on plain string inputs, when it should instead have been returningundefined. 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
codec.decode()for Syntax ErrorsFinal checklist