-
Notifications
You must be signed in to change notification settings - Fork 856
Change ExecError related functions to be associated-fns #1450
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Personally I would update the function get_step_reported_error to take as input an GethExecStep and in that case directly implement it as a From for ExecError but the return type should be changed to Option since the step may not have an error (step.error is optional).
This sounds great to me! Since this is a small PR and the update improvement is also small I would suggest that you implement this approach in this same PR :)
I will review again after the update to submit my approve.
13b5d69
to
0d46aff
Compare
@ed255 I couldn't implement the From for the Option for Option, the options were disturbing the compiler, so I implemented without option and with panic instead. Have a look! |
Ah, Rust doesn't allow you to do that in this module, it would allow you to implement the The Rust std has another trait that may be more appropriate for this case: https://doc.rust-lang.org/std/convert/trait.TryFrom.html if let Ok(error) = ExecError::try_from(step) {
return Ok(Some(error);
} With no unwrap needed in the Edit: The above comment is a nitpick, I think the current approach looks good already! So take this as a suggestion and feel free to ignore it ;) |
Thanks for all the info, it is very helpful (I need these remarks)! I'll try your suggestions after I'm done with #1111. :) |
``The compiler complains if I remove the
The compiler complains when I remove Another thing I tried while playing around was using an
|
How about something like this? It converts the impl TryFrom<&GethExecStep> for ExecError {
type Error = ();
fn try_from(step: &GethExecStep) -> Result<Self, Self::Error> {
// let error: String = step.error.clone().unwrap();
Ok(match step.error.as_ref().ok_or(())?.as_str() {
GETH_ERR_OUT_OF_GAS | GETH_ERR_GAS_UINT_OVERFLOW => {
// NOTE: We report a GasUintOverflow error as an OutOfGas error
let oog_err = OogError::from(&step.op);
ExecError::OutOfGas(oog_err)
}
error => {
if error.starts_with(GETH_ERR_STACK_OVERFLOW) {
ExecError::StackOverflow
} else if error.starts_with(GETH_ERR_STACK_UNDERFLOW) {
ExecError::StackUnderflow
} else {
panic!("Unknown GethExecStep.error: {}", error);
}
}
})
}
} |
LGTM! I just pushed it :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! This looks nicer now :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides from the leftover Edu mentioned, other LGTM!
1ac8f1f
to
dc74cb0
Compare
dc74cb0
to
49d6cc8
Compare
Description
This PR attempts to associate the function
get_step_reported_error
toExecError
.Issue Link
Resolves #1181
Type of change
Contents
Rationale
We wanted to move the function
get_step_reported_error
to animp ExecError
, I also moved the part related toOogError
to its own associated functionFrom<OpCodeId> for OogError
. I changed an if/else block into a match expecting to handle more errors for CREATE/2.Personally I would update the function
get_step_reported_error
to take as input anGethExecStep
and in that case directly implement it as aFrom<GethExecStep> for ExecError
but the return type should be changed toOption<ExecError>
since the step may not have an error (step.error is optional).How Has This Been Tested?
No tests were added as no new functionalities were added.