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

fix: handle decoding errors #80

Merged
merged 4 commits into from
Nov 1, 2024
Merged

fix: handle decoding errors #80

merged 4 commits into from
Nov 1, 2024

Conversation

0xyaco
Copy link
Collaborator

@0xyaco 0xyaco commented Oct 31, 2024

🤖 Linear

Closes GRT-242

Description

  • Catches all errors thrown by decoding bytes properties read from Prophet events
  • Removes ProphetCodec.decode... calls from ProtocolProvider getXXXEvent to use them during actual event processing and not event fetching

Copy link

linear bot commented Oct 31, 2024

jahabeebs
jahabeebs previously approved these changes Oct 31, 2024
Copy link
Collaborator

@jahabeebs jahabeebs left a comment

Choose a reason for hiding this comment

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

looks great 💯

Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

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

looking good 👍 , just some comments

constructor(
public readonly id: string,
public readonly data: ByteArray | Hex,
public readonly err?: Error,
Copy link
Collaborator

Choose a reason for hiding this comment

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

although is optional, you're not using err, maybe want to remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch! The idea was to log the name of the original error to provide more context during debugging to the user. Ended up logging this err's name too

Comment on lines 240 to 252
try {
const disputeStatus = DISPUTE_STATUS_ENUM[status];

if (!disputeStatus) throw new ProphetDecodingError("dispute.status", toHex(status));
else return disputeStatus;
} catch (err) {
throw new ProphetDecodingError(
"dispute.status",
toHex(status.toString()),
err instanceof Error ? err : undefined,
);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it correct to throw, catch and throw the same error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Big 🧠, fixed

try {
AddRequest.buildFromEvent(malformedRequestEvent, registry);

fail("Expecting error");
Copy link
Collaborator

Choose a reason for hiding this comment

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

ooo didn't know this trick

@0xyaco 0xyaco force-pushed the fix/handle-decode-errors branch from f7d5e47 to 6431356 Compare October 31, 2024 18:30
jahabeebs
jahabeebs previously approved these changes Oct 31, 2024
Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

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

just a commit suggestion and is good to go

Comment on lines 242 to 250
try {
disputeStatus = DISPUTE_STATUS_ENUM[status];
} catch (err) {
throw new ProphetDecodingError(
"dispute.status",
toHex(status.toString()),
err instanceof Error ? err : undefined,
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
try {
disputeStatus = DISPUTE_STATUS_ENUM[status];
} catch (err) {
throw new ProphetDecodingError(
"dispute.status",
toHex(status.toString()),
err instanceof Error ? err : undefined,
);
}
disputeStatus = DISPUTE_STATUS_ENUM[status];

try/catch is not needed anymore right?

@0xyaco 0xyaco merged commit 42ee7c4 into dev Nov 1, 2024
5 checks passed
@0xyaco 0xyaco deleted the fix/handle-decode-errors branch November 1, 2024 09:08
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.

3 participants