Skip to content

OdraVM: stop the panic hook from silencing panics - #679

Closed
kubaplas wants to merge 1 commit into
release/2.10.0from
fix/odra-vm-panic-hook
Closed

kubaplas wants to merge 1 commit into
release/2.10.0from
fix/odra-vm-panic-hook

Conversation

@kubaplas

@kubaplas kubaplas commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Summary

The OdraVM panic hook was hiding the output of other panics in the test binary.

  • It replaced the process-wide hook on every contract call. It never passed panics on to the previous hook.
  • After the first OdraVM call, any panic that wasn't a revert or an assertion printed nothing. That covers unwrap(), expect(), panic!() and todo!(), in every test thread of the binary, CasperVM and plain unit tests included. You got FAILED and an empty output.
  • A hook the user had installed was silently dropped.

What changed:

  • Installed once. The hook is set up once (std::sync::Once), keeps the previous hook, and passes every panic that is not an Odra revert to it, assertions included. The standard message, location and RUST_BACKTRACE output work again.
  • Reverts are flagged. OdraVm::revert flags the revert (thread-local) right before it panics. Only flagged panics get the compact Odra output. So reverts in nested calls are recognised, and a user's own panic!("Revert: …") is not.
  • Revert output is unchanged.
  • Side effect: a non-revert panic inside contract code on OdraVM (e.g. unwrap in an entry point) now prints the standard panic message. It is still returned as VmError::Panic.

Before / after

Each scenario makes one OdraVM contract call first. The output is from odra-vm/tests/panic_hook.rs.

unwrap() on None

Before:

child --- FAILED

After:

thread 'child' panicked at odra-vm/tests/panic_hook.rs:65:54:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
child --- FAILED

assert_eq!(1, 2)

Before (custom format, no column, no backtrace support):

💥 assertion `left == right` failed
  left: 1
 right: 2
    ↳ at odra-vm/tests/panic_hook.rs:69
child --- FAILED

After (standard output):

thread 'child' panicked at odra-vm/tests/panic_hook.rs:69:13:
assertion `left == right` failed
  left: 1
 right: 2
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
child --- FAILED

User hook set before the first call (panic!("boom"))

Before:

child --- FAILED

After:

user hook: boom
child --- FAILED

Contract revert (nested call): unchanged

Contract(ContractPackageHash(1000…0000)))::fail
💣 Boom(7)
↳ Stack trace:
  ↳ contract: "Contract"
    ↳ entry point: fail
  ↳ contract: "Contract"
    ↳ entry point: nested
  ↳ caller: Account(AccountHash(0ee6…f309))

Tests

odra-vm/tests/panic_hook.rs re-runs the test binary as a child process for each scenario and checks its stderr: unwrap, assertion, user hook, revert and nested revert. Before the fix, the unwrap, assertion and user-hook tests fail. The two revert tests guard the existing output.

Test plan

  • cargo test (workspace)
  • cargo odra test in examples and examples/ourcoin
  • cargo clippy --all-targets -- -D warnings --allow unexpected_cfgs (root and examples)
  • cargo fmt -- --check

Note: #678 also edits OdraVm::revert, so whichever PR merges second may need a one-line conflict resolved.

🤖 Generated with Claude Code

The OdraVM panic hook replaced the process-wide hook on every contract
call and printed only reverts and assertion failures, so after the first
OdraVM call any other panic in the test binary printed nothing, and a
user-installed hook was dropped.

Install the hook once, keep the previous one and pass every panic that
is not an Odra revert to it. Reverts are flagged by the VM right before
it panics, so a nested revert is recognized and unrelated panics are not.

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

kubaplas commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #680, which combines this PR with #678.

@kubaplas kubaplas closed this Oct 8, 2026
@kubaplas
kubaplas deleted the fix/odra-vm-panic-hook branch October 8, 2026 09:07
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