-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Better handling of error in inherents logic. #14521
Conversation
@@ -110,9 +138,9 @@ pub fn expand_outer_inherent( | |||
if #pallet_names::is_inherent(call) { | |||
is_inherent = true; | |||
if let Err(e) = #pallet_names::check_inherent(call, self) { | |||
result.put_error( | |||
handle_put_error_result(result.put_error( |
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.
I would suggest that we move the if fata_error { return }
part also to a helper function as this is the part that is still important and ensures we bail after seeing one error.
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.
I'm not exactly sure how to factorise it out. something like this?
@@ -138,10 +138,12 @@ pub fn expand_outer_inherent(
if #pallet_names::is_inherent(call) {
is_inherent = true;
if let Err(e) = #pallet_names::check_inherent(call, self) {
- handle_put_error_result(result.put_error(
- #pallet_names::INHERENT_IDENTIFIER, &e
+ let is_fatal = put_error_and_is_error_fatal(
+ result,
+ #pallet_names::INHERENT_IDENTIFIER,
+ &e
));
- if e.is_fatal_error() {
+ if is_fatal {
return result;
}
}
only one fatal error", | ||
), | ||
Err(Error::DecodingFailed(_, _)) | Err(Error::Application(_)) => | ||
log::error!( |
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.
Could use defensive
macro here instead, as we still know these should (almost) never happen.
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.
but defensive
doesn't support renaming of frame_support
contrary to construct_runtime
.
(by renaming mean if somebody rename in its Cargo.toml like this:
s = { version = "*", package = "frame-support" }
)
"Fatal error already reported, unexpected considering there is \ | ||
only one fatal error", | ||
), | ||
Err(_) => |
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.
error variant are different when sp-inherents is compiled with std
or not.
but some test crate use construct_runtime
without having a std
feature. So there is no way to know what is the actual error type.
EDIT: Anyway I will do a follow up issue with proposals for improving inherent code
* impl * trigger CI * Revert "trigger CI" This reverts commit 9426361. * Fix * fix * fix * fix
Currently the code generated by
construct_runtime
for the check of inherent have aexpect
with a quite light proof.In case multiple non fatal error are reported for an inherent the proof is not accurate.
This code makes a more explicit handling of the error and handle this case more appropriately.
IMO we should modify more deeply the inherents logic so that
CheckInherentResult
could handle multiple non fatal error for an inherent. Or only allow one error by inherent. And maybe remove non fatal error if it is considered superfluous.But prior to a more consequent refactor to be discussed I think it is better to have an accurate handling of the result from
put_error
.