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

[types] Ensure string is checked before other types #328

Closed
wants to merge 1 commit into from

Conversation

gregnazario
Copy link
Collaborator

Description

In Javascript, the types are erased, so inputs may not have the types associated. However, string can still be checked, so all inputs should first be checked for if it's a string, then fall back on other options.

This was often manifesting as:

"TypeError: Cannot read properties of undefined (reading 'startsWith')",
    "    at n.fromString (file:///var/task/node_modules/@aptos-labs/ts-sdk/dist/esm/chunk-BZMO6Q6L.mjs:1:422)",
    "    at n.fromHexInput (file:///var/task/node_modules/@aptos-labs/ts-sdk/dist/esm/chunk-BZMO6Q6L.mjs:1:879)",
    "    at new r (file:///var/task/node_modules/@aptos-labs/ts-sdk/dist/esm/chunk-NUBFOYQZ.mjs:1:1038)",
    "    at Runtime.handler (file:///var/task/index.mjs:42:57)",
    "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"

Test Plan

Tested by replacing one of the AccountAddress shortcuts with a toString()

Related Links

In Javascript, the types are erased, so inputs may not have
the types associated.  However, string can still be checked,
so all inputs should first be checked for if it's a string,
then fall back on other options.
@gregnazario gregnazario requested a review from 0xmaayan March 12, 2024 01:23
@gregnazario gregnazario requested a review from a team as a code owner March 12, 2024 01:23
Copy link
Collaborator

@0xmaayan 0xmaayan left a comment

Choose a reason for hiding this comment

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

I am confused about this change and if it is even a fix. Tests seem to pass if passing in a string/non-string from a js file before this change.
Also, the description error complains on passing in an undefined

src/core/hex.ts Show resolved Hide resolved
@gregnazario
Copy link
Collaborator Author

I am confused about this change and if it is even a fix. Tests seem to pass if passing in a string/non-string from a js file before this change. Also, the description error complains on passing in an undefined

Yeah, this was my mistake.

The real question is if we want to bother protecting against undefined everywhere, or just leave it to the user to not mess up.

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

Successfully merging this pull request may close these issues.

2 participants