[NEVER MERGE] Example of migration to unified failure handling system #428
+363
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR demonstrates how to adopt the PoC for the error handling system.
How to play with it
https://github.com/sayon/error-codegen-poc
. It will produce an executable:zksync-error-codegen-cli
era-test-node
and execute:This will generate a crate
zksync_error
in the directory../zksync_error
with all the errors defined inroot.json
anderrors-era-test-node.json
.A proper way of doing it would be to convert
era-test-node
to workspace first and placezksync_error
in the root, but this is a quick demo.The
root.json
file is only for demonstration -- in production, it will be unique for zksync ecosystem and stored in a different, shared repository. The error definitions forera-test-node
are located inerrors-era-test-node.json
.Changes
NB: This is illustrative: the exact DSL in use can be polished and changed in other ways if you like the approach in general.
errors-era-test-node.json
Now if we run
touch era_test_node.log && chmod 000 era_test_node.log && cargo run
we will see:main.rs
so that failure of log creation results in this custom error , rather than a wildcard.Now if we run
touch era_test_node.log && chmod 000 era_test_node.log && cargo run
we will see:The exact output can be of course tuned to (conditionally) hide the technical details.