Giter Club home page Giter Club logo

Comments (7)

obycode avatar obycode commented on September 22, 2024 1

This is still an open item.

from clarity-wasm.

smcclellan avatar smcclellan commented on September 22, 2024

@csgui to see if this is still an issue.

from clarity-wasm.

csgui avatar csgui commented on September 22, 2024

Thanks @obycode

from clarity-wasm.

csgui avatar csgui commented on September 22, 2024

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.

obycode avatar obycode commented on September 22, 2024

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:

  1. 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)))?;
  1. In call_function (clar2wasm/src/wasm_utils.rs:1286) (note the other TODO 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.

obycode avatar obycode commented on September 22, 2024

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.

csgui avatar csgui commented on September 22, 2024

Fixed by #379

from clarity-wasm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.