Code Monkey home page Code Monkey logo

Comments (7)

liamappelbe avatar liamappelbe commented on May 28, 2024 1

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.

from wasm.

liamappelbe avatar liamappelbe commented on May 28, 2024

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 🙃.

from wasm.

liamappelbe avatar liamappelbe commented on May 28, 2024

@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.

from wasm.

juancastillo0 avatar juancastillo0 commented on May 28, 2024

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!

from wasm.

juancastillo0 avatar juancastillo0 commented on May 28, 2024

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!

from wasm.

liamappelbe avatar liamappelbe commented on May 28, 2024

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.

from wasm.

juancastillo0 avatar juancastillo0 commented on May 28, 2024

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;
}",
    );
}

from 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.