Comments (7)
This is still an open item.
from clarity-wasm.
@csgui to see if this is still an issue.
from clarity-wasm.
Thanks @obycode
from clarity-wasm.
Note: On the file below, some tests are being ignored due this issue. Remove ignored
tag when it's fixed.
conditionals.rs
from clarity-wasm.
In standard.wat, we have defined the function stdlib.runtime-error
:
;; The error code is one of:
;; 0: overflow
;; 1: underflow
;; 2: divide by zero
;; 3: log of a number <= 0
;; 4: expected a non-negative number
;; 5: buffer to integer expects a buffer length <= 16
;; 6: panic
;; 7: short return
(func $stdlib.runtime-error (param $error-code i32)
;; TODO: Implement runtime error
unreachable
)
This TODO
is the goal of this issue. This function gets called whenever we need to trigger a runtime error during a wasm execution. The possible causes of these runtime errors are enumerated in the comment. If we trigger one of these runtime errors today, we will see the execution return something like:
Err(Wasm(Runtime(error while executing at wasm backtrace:
0: 0x2e33 - <unknown>!stdlib.runtime-error
1: 0x2ad8 - <unknown>!<wasm function 105>
Instead, we need to catch this wasm runtime error, and convert it to a clarity error, based on that error code that is passed into this function. For example:
Err(ShortReturn(ExpectedValue(Int(1))))
This should happen wherever we call
a wasm function:
- In
initialize_contract
(clar2wasm/src/initialize.rs:369):
top_level
.call(&mut store, &[], results.as_mut_slice())
.map_err(|e| Error::Wasm(WasmError::Runtime(e)))?;
- In
call_function
(clar2wasm/src/wasm_utils.rs:1286) (note the otherTODO
here from @krl):
func.call(&mut store, &wasm_args, &mut results)
.map_err(|e| {
// TODO: If the root cause is a clarity error, we should be able to return that,
// but it is not cloneable, so we can't return it directly.
// If the root cause is a trap from our Wasm code, then we need to translate
// it into a Clarity error.
// See issue stacks-network/clarity-wasm#104
// if let Some(vm_error) = e.root_cause().downcast_ref::<crate::vm::errors::Error>() {
// vm_error.clone()
// } else {
// Error::Wasm(WasmError::Runtime(e))
// }
Error::Wasm(WasmError::Runtime(e))
})?;
from clarity-wasm.
After these errors are properly mapped, then we should remove the .map_err(|_| ())
in interpret
and evaluate
so that the errors between the two runtimes can be properly compared in the tests.
from clarity-wasm.
Fixed by #379
from clarity-wasm.
Related Issues (20)
- Improve `contract-call?` implementation HOT 1
- Large arguments for hashing functions causes OOM
- Node crashes when an undefined trait is called HOT 3
- Compiler allows reusing of the same argument name when defining a function HOT 2
- Err-returning function losing wrapped value
- Dynamic `contract-call?` doesn't work if the trait name is re-binded HOT 1
- Creating large list with literals fails to compile because of too many locals
- Property tests for the stdlib `skip` functions
- Improve type checker HOT 1
- Property test for `concat_crosscheck` HOT 2
- Optimize `print` memory usage HOT 1
- Revisit typechecker workarounds HOT 2
- Check if `typechecker_workaround` works for nested `filter`/`fold` expressions HOT 3
- index-of function failing in ClarityV1
- define-data-var function issue in ClarityV1
- Typechecking issue for `index-of` in Clarity1 HOT 2
- No more need for tuple signature conversion functions HOT 2
- Test node instance issue: Wasm(UnableToLoadModule(incompatible import type for clarity::contract_call...
- Ensure shortcircuiting function body with runtime errors does not introduce issues
- NFT functions issue for clarity V1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clarity-wasm.