dart-archive/wasm

WasmError: This case is not (yet) supported. Please file an issue on pkg:wasm

juancastillo0 opened this issue · 7 comments

Hi! Thanks for your work!

I was receiving the error message WasmError: This case is not (yet) supported. Please file an issue on pkg:wasmwhen trying out the package.

You can run the test in https://github.com/juancastillo0/dart-parser/blob/main/test/parser_test.dart to receive the same error. The wasm file was generated using wasm-pack build for the Rust project in the dart-parser-wasm folder of the same repository. It uses wasm-pack and wasm-bidgen.

WasmError: This case is not (yet) supported. Please file an issue on pkg:wasm.
WasmRuntime.maybeThrowTrap
package:wasm/src/runtime.g.dart:610
WasmRuntime.call
package:wasm/src/runtime.g.dart:680
WasmFunction.apply
package:wasm/src/module.dart:403
_Instance.lookupFunction.<fn>
package:dart_fixer_test/…/wasm/wasm_interop_native.dart:108
DartParserWasmModule.parse
package:dart_fixer_test/…/wasm/dart_parser_wasm_bg.dart:122
DartParser.parse
package:dart_fixer_test/wasm/dart_parser_wasm.dart:44
main.<fn>

The same error was also happening when trying some models in https://github.com/juancastillo0/tensorflow_dart.

Please let me know if there is something else I can do. I could try to make a PR.

Thanks!

maybeThrowTrap indicates some sort of error happened inside the wasm code when you tried to call that function. I'll try to dig into why you hit this edge case, but if you're not expecting this function to throw an error, then this probably also indicates a problem on your end that you should try to debug.

EDIT: To be clear, if I fix this bug, the fix will still mean that this function throws an exception, it'll just be a different exception 🙃.

@juancastillo0 Are you running that test on a branch or something? When I try to run that test on main I get this error:

$ dart test
Building package executable... (6.9s)
Built test:test.
00:01 +0 -1: loading test/parser_test.dart [E]                                 
  Failed to load "test/parser_test.dart":
  test/parser_test.dart:1:8: Error: Error when reading 'lib/test-file.dart': No such file or directory
  import 'package:dart_fixer_test/test-file.dart';
         ^
  test/parser_test.dart:16:15: Error: Method not found: 'File'.
          await File('./lib/wasm/dart_parser_wasm.wasm').readAsBytes();
                ^^^^

To run this test again: dart test test/parser_test.dart -p vm --plain-name 'loading test/parser_test.dart'
00:01 +0 -1: Some tests failed.

Hi! Thanks for the response.

Sorry the test was importing File from another place. I already pushed the fix.

I just tested this with a clean repository clone:

dart pub get

dart run wasm:setup

dart test

Also added a test for executing Dart's print from wasm. That is working fine.

I am working with strings, maybe I am not encoding them properly, or something. What I did was translate the javascript generated from wasm-pack build into this Dart file. I will try to find the error.

Thanks!

You are right, everything is working fine, the Rust was just panicking. I changed the input string to parse and it works.
I think we can close this issue, unless you want to leave it as something to expose the wasm exception in some way.

Thank you for your work and for trying out the code!

Great. But yeah, I'll keep this issue open, because I still don't really understand how this edge case was triggered, and it's good to have your test as a reliable repro.

Not sure if it is helpful, but the specific error in this case was this one:

thread 'test_error' panicked at 'StringLiteral', src/parser.rs:96:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
   2: dart_parser_pest::parser::ParseCtx::parse_ast
             at ./src/parser.rs:96:9
   3: <dart_parser_pest::ast::ConfigurableUri as dart_parser_pest::parser::RuleModel>::parse
             at ./src/ast.rs:7901:18
   4: dart_parser_pest::parser::ParseCtx::parse_ast
             at ./src/parser.rs:99:21
   5: <dart_parser_pest::ast::ImportSpecification as dart_parser_pest::parser::RuleModel>::parse
             at ./src/ast.rs:7665:31
   6: dart_parser_pest::parser::ParseCtx::parse_ast
             at ./src/parser.rs:99:21
   7: <dart_parser_pest::ast::LibraryImport as dart_parser_pest::parser::RuleModel>::parse
             at ./src/ast.rs:7618:35
   8: dart_parser_pest::parser::ParseCtx::parse_ast
             at ./src/parser.rs:99:21
   9: <dart_parser_pest::ast::ImportOrExport as dart_parser_pest::parser::RuleModel>::parse
             at ./src/ast.rs:7559:66
  10: dart_parser_pest::parser::ParseCtx::parse_ast
             at ./src/parser.rs:99:21
  11: dart_parser_pest::parser::ParseCtx::parse_list
             at ./src/parser.rs:81:25
  12: <dart_parser_pest::ast::LibraryDeclaration as dart_parser_pest::parser::RuleModel>::parse
             at ./src/ast.rs:7494:31
  13: dart_parser_pest::parser::ParseCtx::parse_ast
             at ./src/parser.rs:99:21
  14: dart_parser_pest::parser::ParseCtx::parse_str
             at ./src/parser.rs:28:13
  15: dart_parser_pest::parser::ParseOutput::from_str
             at ./src/parser.rs:119:35
  16: dart_parser_pest::parse_to_output
             at ./src/lib.rs:18:11
  17: dart_parser_pest::parse_to_json
             at ./src/lib.rs:8:18
  18: dart_parser_pest::test_error
             at ./src/lib.rs:47:5
  19: dart_parser_pest::test_error::{{closure}}
             at ./src/lib.rs:46:1
  20: core::ops::function::FnOnce::call_once
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
  21: core::ops::function::FnOnce::call_once
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5

The error was triggered by this assert:

assert!(self.is_rule_next(T::rule()), "{:?}", T::rule());

And the Rust test function was this one, using the same string that I used in the Dart test:

#[test]
fn test_error() {
    parse_to_json(
        &"
import './relative.dart';

class ModelC {
    /// Docs
    final String a;

    const ModelC(this.a);

    int get length => a.length;
}",
    );
}

Oh, I remember now. Basically, I used to have it just throw the error message at this point. But I didn't know how to write a test for that case, since I didn't know how to write C code that would trigger a trap. So since I didn't want to commit untested code, I removed that feature. Looks like a Rust assert will do the trick.