Skip to content

refactor(crt): add exhaustive wasmtime trap classification#15755

Merged
darioush merged 3 commits into
near:masterfrom
darioush:wasmtime-exhaustive-traps
May 19, 2026
Merged

refactor(crt): add exhaustive wasmtime trap classification#15755
darioush merged 3 commits into
near:masterfrom
darioush:wasmtime-exhaustive-traps

Conversation

@darioush

Copy link
Copy Markdown
Contributor

Introduces a TrapClassification mirror enum that we own, replacing the raw wasmtime::Trap match in into_vm_error. Since wasmtime::Trap is #[non_exhaustive], the catch-all arm silently swallows new variants on Wasmtime upgrades. The new From<Trap> impl explicitly classifies every current variant, and a unit test iterates all discriminants via Trap::from_u8 to ensure no variant lands in Unknown. Each disabled-proposal variant is annotated with the Wasm proposal it belongs to (fuel, threads, GC/function-references, component model, component-model async, stack switching, pulley).

@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.19048% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.97%. Comparing base (bd7f54e) to head (1527d68).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
runtime/near-vm-runner/src/wasmtime_runner/mod.rs 47.05% 9 Missing ⚠️
...-runner/src/wasmtime_runner/trap_classification.rs 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15755      +/-   ##
==========================================
- Coverage   69.99%   69.97%   -0.02%     
==========================================
  Files         938      939       +1     
  Lines      198599   197841     -758     
  Branches   198599   197841     -758     
==========================================
- Hits       139003   138439     -564     
+ Misses      54926    54752     -174     
+ Partials     4670     4650      -20     
Flag Coverage Δ
pytests-nightly 1.13% <0.00%> (+<0.01%) ⬆️
unittests 69.39% <76.19%> (-0.03%) ⬇️
unittests-nightly 69.64% <76.19%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@darioush darioush requested a review from jakmeier May 18, 2026 18:23
@darioush darioush marked this pull request as ready for review May 18, 2026 18:23
@darioush darioush requested a review from a team as a code owner May 18, 2026 18:23
@darioush darioush requested review from Copilot, ssavenko-near and walnut-the-cat and removed request for walnut-the-cat May 18, 2026 18:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Wasmtime trap handling in near-vm-runner by introducing an owned, exhaustive trap classification enum to avoid silently swallowing new wasmtime::Trap variants (which is #[non_exhaustive]) on Wasmtime upgrades.

Changes:

  • Add TrapClassification (mirror of wasmtime::Trap) with explicit mapping of all currently known trap variants and a fallback Unknown.
  • Update IntoVMError for wasmtime::Error to convert traps via TrapClassification instead of matching wasmtime::Trap directly.
  • Add a unit test that iterates Trap::from_u8 over all discriminants and asserts no current trap maps to Unknown; extend cspell wordlist.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
runtime/near-vm-runner/src/wasmtime_runner/trap_classification.rs New owned trap mirror enum + exhaustive classification logic and a regression test to catch new Wasmtime trap variants.
runtime/near-vm-runner/src/wasmtime_runner/mod.rs Switch trap-to-NEAR-error mapping to go through TrapClassification.
cspell.json Add “Waitable” to accommodate new trap variant naming in code/comments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +33 to +36
fn from(trap: Trap) -> Self {
match trap {
Trap::StackOverflow => Self::StackOverflow,
Trap::MemoryOutOfBounds => Self::MemoryOutOfBounds,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Copilot suggestion has a valid point about readability. Switched to using explicit bindings.

🤖 -- Claude on behalf of Darioush

@darioush darioush added this pull request to the merge queue May 19, 2026
Merged via the queue into near:master with commit 6960073 May 19, 2026
32 checks passed
@darioush darioush deleted the wasmtime-exhaustive-traps branch May 19, 2026 13:35
pugachAG pushed a commit that referenced this pull request May 27, 2026
Introduces a `TrapClassification` mirror enum that we own, replacing the
raw `wasmtime::Trap` match in `into_vm_error`. Since `wasmtime::Trap` is
`#[non_exhaustive]`, the catch-all arm silently swallows new variants on
Wasmtime upgrades. The new `From<Trap>` impl explicitly classifies every
current variant, and a unit test iterates all discriminants via
`Trap::from_u8` to ensure no variant lands in `Unknown`. Each
disabled-proposal variant is annotated with the Wasm proposal it belongs
to (fuel, threads, GC/function-references, component model,
component-model async, stack switching, pulley).
@github-actions github-actions Bot mentioned this pull request May 27, 2026
11 tasks
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.

4 participants