Skip to content

fix(wasm): enable C++ exception catching in the Emscripten build - #2

Closed
charlieh0tel wants to merge 2 commits into
masterfrom
fix-wasm-exceptions
Closed

charlieh0tel wants to merge 2 commits into
masterfrom
fix-wasm-exceptions

Conversation

@charlieh0tel

@charlieh0tel charlieh0tel commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Emscripten disables C++ exception catching by default: throw aborts the module and catch blocks are elided. This adds -fexceptions to both compile and link options for the nec2pp_wasm target.

  • nec_context::simulate uses throw 1 / catch (int) to unwind a finished solve (src/nec_context.cpp:1126, :1142, :1153).
  • nec_process_input (src/nec_wasm.cpp) catches nec_exception to return -2 with an error message.

Note: the WASM entry point is still a stub and doesn't call simulate() yet, so today the error-handling path is the one that matters; the solve path will once it's wired up.

Also adds tests/wasm_smoke.js, run in the CI wasm job: it loads the module under Node, feeds nec_process_input a deck that makes the geometry parser throw, and requires rc -2 with the error message in the output.

Test plan

  • node tests/wasm_smoke.js nec2pp.js passes against a build of this branch
  • Same test fails against a build of master (the exception escapes into JS as a raw pointer)
  • CI wasm job passes

🤖 Generated with Claude Code

charlieh0tel and others added 2 commits September 28, 2026 16:09
Emscripten disables exception catching by default, so throws abort and
catch blocks are elided. nec_context uses `throw 1` to unwind a finished
solve, and nec_process_input relies on catching nec_exception to report
errors. Pass -fexceptions at both compile and link time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CI wasm job only checked that nec2pp.js/nec2pp.wasm were produced.
Load the module under Node, feed nec_process_input a deck that makes the
geometry parser throw, and require rc -2 with the error in the output.
Without exception catching the throw escapes into JS and the test fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@charlieh0tel

Copy link
Copy Markdown
Owner Author

Closing: not sending WASM-target fixes upstream (tmolteno#136 closed). nec2-js builds WASM with its own emcc script, which already passes -fexceptions. Branch kept for the smoke test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant