Git Product home page Git Product logo

Comments (5)

piaoger avatar piaoger commented on May 20, 2024

just had more tests and found it caused by following line about config. Take a look at The manifest but still cannot figure out how to use it for testing :)

    // remove to fix runtime error
    // config::get("thing").expect("'thing' key set in config");
    let config = String::from("something");

from extism.

bhelx avatar bhelx commented on May 20, 2024

Did you copy paste the code from https://extism.org/docs/write-a-plugin/rust-pdk ?

I ran your code through the extism cli:

echo "Hello World" | extism call wasm_web_plugin.wasm count_vowels
Traceback (most recent call last):
  File "/Users/ben/.local/bin/extism", line 558, in <module>
    main()
  File "/Users/ben/.local/bin/extism", line 553, in main
    r = plugin.call(args.function, input, parse=None)
  File "/opt/homebrew/lib/python3.10/site-packages/extism/extism.py", line 201, in call
    self._check_error(
  File "/opt/homebrew/lib/python3.10/site-packages/extism/extism.py", line 183, in _check_error
    raise Error(ffi.string(error).decode())
extism.extism.Error: Call failed

Caused by:
    0: error while executing at wasm backtrace:
           0: 0x74c3 - <unknown>!__rust_start_panic
           1: 0x74b7 - <unknown>!rust_panic
           2: 0x7487 - <unknown>!std::panicking::rust_panic_with_hook::he04cb00575f2a1e3
           3: 0x6b18 - <unknown>!std::panicking::begin_panic_handler::{{closure}}::hb733f0aa505760cf
           4: 0x6a45 - <unknown>!std::sys_common::backtrace::__rust_end_short_backtrace::h6beefa0bcab220bc
           5: 0x70db - <unknown>!rust_begin_unwind
           6: 0x803a - <unknown>!core::panicking::panic_fmt::h586d720a90aa8503
           7: 0x9134 - <unknown>!core::panicking::panic_display::he96fafaefe672510
           8: 0x90ae - <unknown>!core::panicking::panic_str::h8b2f06f6f011655d
           9: 0x907c - <unknown>!core::option::expect_failed::h1e9a9cbb22bbd6ac
          10:  0xcf4 - <unknown>!count_vowels
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable to may show more debugging information
    1: wasm trap: wasm `unreachable` instruction executed

The line of interest to you should be:

           9: 0x907c - <unknown>!core::option::expect_failed::h1e9a9cbb22bbd6ac

Keep in mind that any of these lines may trap and just there to demonstrate the API:

    let a = var::get("a")?.expect("variable 'a' set");
    let a = String::from_utf8(a).expect("string from varible value");
    let config = config::get("thing").expect("'thing' key set in config");

Here is a simplified version of that example:

use extism_pdk::*;
use serde::Serialize;

const VOWELS: &[char] = &['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'];

#[derive(Serialize)]
struct TestOutput {
    pub count: i32,
}

#[plugin_fn]
pub unsafe fn count_vowels(input: String) -> FnResult<Json<TestOutput>> {
    let mut count = 0;
    for ch in input.chars() {
        if VOWELS.contains(&ch) {
            count += 1;
        }
    }

    let output = TestOutput {
        count,
    };
    Ok(Json(output))
}

from extism.

piaoger avatar piaoger commented on May 20, 2024

@bhelx
Thanks for your reply.I had already modified my code and passed the test in playgound.

My current question is about where and how to privide manifest/config.

from extism.

nilslice avatar nilslice commented on May 20, 2024

@piaoger currently there is no support to add a config through the playground, but you can do it via the CLI using --set-config to pass a map of key/value pairs, or --config to set a single key=value pair.

An example of using --set-config can be seen here:

https://github.com/extism/assemblyscript-pdk/blob/main/.github/workflows/ci.yml#L55

from extism.

piaoger avatar piaoger commented on May 20, 2024

@nilslice thanks for the information :)

from extism.

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.