This repository was archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
feat!: Provide runtime callstacks for brillig failures and return errors in acvm_js #523
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e384108
feat: brillig errors with callstacks
sirasistant e11b810
feat: improve error handling
sirasistant db5ca91
fix: switch to raw error
sirasistant 4448d09
Merge branch 'master' into arv/brillig_call_stacks
sirasistant cfd9b1f
Merge branch 'master' into arv/brillig_call_stacks
sirasistant f29dd96
feat: improve js error building
sirasistant 1336cef
feat: update message if assertion is present
sirasistant 9efa6ac
Merge branch 'master' into arv/brillig_call_stacks
sirasistant e31bf7a
fix: remove old js file
sirasistant abd2ff5
docs: add doc comment on error call stack
sirasistant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| use acvm::acir::circuit::OpcodeLocation; | ||
| use js_sys::{Array, Error, JsString, Reflect}; | ||
| use wasm_bindgen::prelude::{wasm_bindgen, JsValue}; | ||
|
|
||
| #[wasm_bindgen(typescript_custom_section)] | ||
| const EXECUTION_ERROR: &'static str = r#" | ||
| export type ExecutionError = Error & { | ||
| callStack?: string[]; | ||
| }; | ||
| "#; | ||
|
|
||
| /// JsExecutionError is a raw js error. | ||
| /// It'd be ideal that execution error was a subclass of Error, but for that we'd need to use JS snippets or a js module. | ||
| /// Currently JS snippets don't work with a nodejs target. And a module would be too much for just a custom error type. | ||
| #[wasm_bindgen] | ||
| extern "C" { | ||
| #[wasm_bindgen(extends = Error, js_name = "ExecutionError", typescript_type = "ExecutionError")] | ||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| pub type JsExecutionError; | ||
|
|
||
| #[wasm_bindgen(constructor, js_class = "Error")] | ||
| fn constructor(message: JsString) -> JsExecutionError; | ||
| } | ||
|
|
||
| impl JsExecutionError { | ||
| /// Creates a new execution error with the given call stack. | ||
| /// Call stacks won't be optional in the future, after removing ErrorLocation in ACVM. | ||
| pub fn new(message: String, call_stack: Option<Vec<OpcodeLocation>>) -> Self { | ||
| let mut error = JsExecutionError::constructor(JsString::from(message)); | ||
| let js_call_stack = match call_stack { | ||
| Some(call_stack) => { | ||
| let js_array = Array::new(); | ||
| for loc in call_stack { | ||
| js_array.push(&JsValue::from(format!("{}", loc))); | ||
| } | ||
| js_array.into() | ||
| } | ||
| None => JsValue::UNDEFINED, | ||
| }; | ||
|
|
||
| error.set_property("callStack", js_call_stack); | ||
|
|
||
| error | ||
| } | ||
|
|
||
| fn set_property(&mut self, property: &str, value: JsValue) { | ||
| assert!( | ||
| Reflect::set(self, &JsValue::from(property), &value).expect("Errors should be objects"), | ||
| "Errors should be writable" | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.