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

chore: make integers errors more explicit #1314

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

zakarialounes
Copy link
Contributor

For easy debugging.

@@ -55,7 +55,7 @@ export class Uint32 implements Integer, WithByteConverters {

public static fromString(str: string): Uint32 {
if (!str.match(/^[0-9]+$/)) {
throw new Error("Invalid string format");
throw new Error("Invalid string format. Found: " + str);
Copy link
Member

Choose a reason for hiding this comment

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

Can you put the values in quotes? This makes it easier to find begin and end in the error messages and allows debugging empty string inputs.

Probably easier to write with a template string.

throw new Error(`Invalid string format. Found: '${str}'`);

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had also thought about it, but I based it on

throw new Error("Invalid value in byte. Found: " + bytes[i]);

I will adapt to reflect your suggestion.

@@ -238,10 +238,10 @@ export class Uint64 implements Integer, WithByteConverters {

private constructor(data: BN) {
if (data.isNeg()) {
throw new Error("Input is negative");
throw new Error("Input is negative. Found: " + data);
Copy link
Member

Choose a reason for hiding this comment

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

Does that give you a proper debug representation of a BN?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, I will adapt this with the call toString()

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

LGTM overall

@zakarialounes
Copy link
Contributor Author

Should be good @webmaster128

@zakarialounes
Copy link
Contributor Author

any news @webmaster128?

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.

None yet

2 participants