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

Improve ethers.utils.parseUnits error message #981

Closed
jeffprestes opened this issue Aug 1, 2020 · 8 comments
Closed

Improve ethers.utils.parseUnits error message #981

jeffprestes opened this issue Aug 1, 2020 · 8 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@jeffprestes
Copy link

Getting this error:
ethers-5.0.umd.min.js:1 Uncaught Error: invalid decimal value (argument="value", value=1, code=INVALID_ARGUMENT, version=bignumber/5.0.5)

in this statement

    value: ethers.utils.parseUnits(amount, "gwei"),
  };```

in amount variable the value is 1

In ethers 4.0 it works.
@ricmoo
Copy link
Member

ricmoo commented Aug 1, 2020

The value must be a string... if it worked in v4, that was probably a bug... Numbers are not safe to use in parseUnits as arithmetic underflow could occur.

The string "1" should be fine though. :)

@jeffprestes
Copy link
Author

You're right. Thanks for the quick answer!
BTW, I'll let update the issue to improve the error message to let this situation more clear to lib user.
I wish I could help but as I am not typescript I can't do it unfortunately.

@jeffprestes jeffprestes changed the title ethers.utils.parseUnits error Improve ethers.utils.parseUnits error message Aug 1, 2020
@jeffprestes
Copy link
Author

logger.throwArgumentError("invalid decimal value", "value", value);

@ricmoo
Copy link
Member

ricmoo commented Aug 2, 2020

That’s is a completely fair ask.

I’m in the midst of moving this week, but will get to this soon. :)

@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. labels Aug 20, 2020
@ricmoo
Copy link
Member

ricmoo commented Oct 8, 2020

This has been fixed in 5.0.17. If you have any problems, please let me know.

Thanks! :)

@ricmoo ricmoo closed this as completed Oct 8, 2020
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Oct 8, 2020
@jeffprestes
Copy link
Author

Thanks Ric. I believe it's going to help some Devs.

@CodeLuca
Copy link

helped me a ton

@mairura
Copy link

mairura commented Jul 22, 2022

This is helpful. I appreciate alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

4 participants