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 error types #89

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

Conversation

idky137
Copy link
Contributor

@idky137 idky137 commented Nov 2, 2024

Fixes the errors returned for get_block, get_block_range, get_nullifiers, get_nullifiers_range RPCs.

@idky137 idky137 added bug Something isn't working ZGM1 Issues that need to be resolved for the completion of the Zaino dev grant milestone 1 labels Nov 2, 2024
@idky137 idky137 marked this pull request as ready for review November 2, 2024 13:30
This was referenced Nov 2, 2024
Copy link
Contributor

@Oscar-Pepper Oscar-Pepper left a comment

Choose a reason for hiding this comment

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

im not sure if i consider the error stuff blocking but i think it could be improved. the "let _ =" i believe is a mistake here and i consider blocking, we should not have wrapped results lingering around IMO

@@ -126,15 +126,15 @@ impl JsonRpcConnector {
if body_str.contains("Work queue depth exceeded") {
if attempts >= max_attempts {
return Err(JsonRpcConnectorError::new(
"Work queue depth exceeded after multiple attempts",
"Error: The node's rpc queue depth was exceeded after multiple attempts",
Copy link
Contributor

Choose a reason for hiding this comment

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

im not sure if we should consider this blocking but I think we should try to avoid repeated Error: Error: Error status xxxx in the format display of error types. Im not sure what the standard practice is but my preferred method is to not have "Error:" in the format display of error types (or this case strings which we should change to error types and implement fmt::display at some point soon). The idea here is all the different error types can navigate many different levels and enums without "collecting" more "Error:"s at the start. then finally, at the top level where it will be called directly by the user/consumer we put "Error: {}" in the final fmt:display. I have seen you have done this later in the PR but i havent checked this is the top level fmt::display.

Copy link
Contributor

Choose a reason for hiding this comment

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

the final error printed to user should preferably look like this:
"Error: Serialisation error. 2nd level error. 2nd level thing failed." for example. IMO

Copy link
Contributor

Choose a reason for hiding this comment

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

this would be made up of the top level error message for example in an eprintln:
match result {
Ok(_) => (),
Err(top_level_error_enum) => eprintln!"Error: {}", top_level_error_enum)
}

then the top level error enum with thiserror macro:
pub enum TopLevelError {
#error("Serialisation error. {0}")
SerialisationFailed(SerialisationError),
#error("Some other error. {0}")
SomeOtherError,
}

then serialisation error enum:
enum SerialisationError {
#error("2nd level thing failed. {0}")
2ndLevelThingFailed(2ndLevelThing),
#error("2nd level other thing failed. {0}")
2ndLevelOtherThing,
}

where 2ndLevelthing might be some struct with useful info like if its a block height for example it would produce:
"Error: Serialisation error. 2nd level error. 2nd level thing failed. Blockheight: 10"

{
break;
if height > chain_height {
let _ = channel_tx
Copy link
Contributor

Choose a reason for hiding this comment

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

sometimes the compliler asks to put "let _ = " but i think this is bad advice. sometimes its useful to use this to keep something in scope but i still prefer "let _unused_name_of_thing =" in stead of just underscore for that. in this case i believe you need to actually handle your result with a match and error handling or atleast an expect if it cant fail

{
break;
if height > chain_height {
let _ = channel_tx
Copy link
Contributor

Choose a reason for hiding this comment

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

see comment above about "let _ ="

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ZGM1 Issues that need to be resolved for the completion of the Zaino dev grant milestone 1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants