Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error message from WebAssembly + JS #426

Open
jerinphilip opened this issue Jun 21, 2022 · 1 comment
Open

Confusing error message from WebAssembly + JS #426

jerinphilip opened this issue Jun 21, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@jerinphilip
Copy link
Contributor

I'm trying to get an assert working for #425; Despite no issues in WebAssembly, the following error message is dumped:

Using fallback gemm implementation
 <p>Hallo Welt!</p>   <p>Wiedersehen Welt!</p> 
string
DocumentFragment {}
<p>Hallo Welt!</p>
Aborted(undefined)
undefined:448
 var e = new WebAssembly.RuntimeError(what);
         ^

RuntimeError: Aborted(undefined). Build with -s ASSERTIONS=1 for more info.
    at abort (eval at <anonymous> (/home/jerin/code/bergamot-translator/build-wasm/node-test.js:1:1), <anonymous>:448:10)
    at assert (eval at <anonymous> (/home/jerin/code/bergamot-translator/build-wasm/node-test.js:1:1), <anonymous>:116:3)
    at Object.onRuntimeInitialized (/home/jerin/code/bergamot-translator/build-wasm/node-test.js:112:3)

The following is the relevant source:

  ...
  // Construct std::vector<std::string> inputs;
  const input = new Module.VectorString();
  input.push_back('<p> Hello world! </p> <p> Goodbye World! </p>');

  // Construct std::vector<ResponseOptions>
  const options = new Module.VectorResponseOptions();
  options.push_back({qualityScores: false, alignment: true, html: true});

  // Translate our batch (of 1)
  const output = service.translate(model, input, options);

  // Get output from std::vector<Response>
  const translation = output.get(0).getTranslatedText()
  console.log(translation)
  console.log(typeof (translation));

  const fragment = JSDOM.fragment(translation)
  console.log(fragment)
  console.log(fragment.firstElementChild.outerHTML)
  assert(fragment.childElementCount === 1); // This fails, because 2, and has nothing to do with WebAssembly?
@jelmervdl
Copy link
Member

This happens because assert() is defined by bergamot-translation-worker.js, the Emscripten runtime code:

function assert(condition, text) {
 if (!condition) {
  abort(text);
 }
}

// ...

function abort(what) {
 what = "Aborted(" + what + ")";
 err(what);
 ABORT = true;
 EXITSTATUS = 1;
 what += ". Build with -s ASSERTIONS=1 for more info.";
 var e = new WebAssembly.RuntimeError(what);
 throw e;
}

You could replace assert() with console.assert() which is the more common API for it in Javascript. Downside: console.assert just prints a message but does not stop the program from continuing. So it isn't really equivalent.

@jelmervdl jelmervdl added the documentation Improvements or additions to documentation label Jul 14, 2022
jelmervdl added a commit to jelmervdl/bergamot-translator that referenced this issue Jul 23, 2022
XapaJIaMnu added a commit that referenced this issue Jan 18, 2023
* Expand the node-test.js example code with documentation

Is there a better way to document code than by providing an annotated & working example of it? Just listing all the exposed methods feels like giving people a box of bricks and expecting them to build a house with it.

* Use @jerin's feedback to simplify node-test.js explanations

* Use native `console.assert` instead

See #426 for an explanation

* Fix comment

Co-authored-by: Nikolay Bogoychev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants