Skip to content

feat(testing): add matches: and any arms to execution error assertion macros#2893

Closed
AlgofootPrint wants to merge 1 commit into
0xMiden:nextfrom
AlgofootPrint:feat/extend-execution-error-macros
Closed

feat(testing): add matches: and any arms to execution error assertion macros#2893
AlgofootPrint wants to merge 1 commit into
0xMiden:nextfrom
AlgofootPrint:feat/extend-execution-error-macros

Conversation

@AlgofootPrint
Copy link
Copy Markdown

Summary

Closes #2807

Extends assert_execution_error! and assert_transaction_executor_error! in
crates/miden-testing/src/utils.rs with two new arms (keeping the : in
matches: per @Keinberger's preference for consistency with #2805):

matches: $pat $(if $guard)? - pattern-matches the inner ExecutionError
directly, with an optional guard expression. Covers non-FailedAssertion variants
and FailedAssertion with a specific err_code guard:

// outer ExecutionError variant
assert_execution_error!(result, matches: ExecutionError::CycleLimitExceeded(_));

// inner OperationError variant
assert_execution_error!(result, matches:
    ExecutionError::OperationError { err: OperationError::DivideByZero, .. }
);

// FailedAssertion with specific err_code guard
assert_execution_error!(result, matches:
    ExecutionError::OperationError {
        err: OperationError::FailedAssertion { err_code, .. }, ..
    } if err_code == Felt::new(0x1234)
);

any - accepts any Err, panics on Ok:

assert_execution_error!(result, any);

For assert_transaction_executor_error! the same two arms are added; the outer
TransactionExecutorError::TransactionProgramExecutionFailed(...) wrapper is
handled internally so `` matches ExecutionError directly.

Tests

Three new unit tests in utils.rs:

  • assert_execution_error_any - any arm with a FailedAssertion
  • assert_execution_error_matches_divide_by_zero - matches: without guard on DivideByZero
  • assert_execution_error_matches_with_err_code_guard - matches: with if guard on err_code

A compile-time-only check verifies the any arm type-checks for
assert_transaction_executor_error!.

Not included

The Rust SDK assert_with_code / assertz_with_code / assert_eq_with_code
helpers - those cross into compiler/SDK territory and need coordination with the
compiler team as noted by @Keinberger.

Extends assert_execution_error! and assert_transaction_executor_error!
with two new arms:

- matches: $pat $(if $guard)? -- pattern-matches the inner ExecutionError
  directly, with an optional guard expression. Allows testing non-
  FailedAssertion variants (e.g. DivideByZero, CycleLimitExceeded) and
  FailedAssertion with a specific err_code guard, without writing a
  manual match statement.

- any -- accepts any Err result; useful when the test only cares that
  execution failed, not which error was produced.

Closes 0xMiden#2807
@mmagician
Copy link
Copy Markdown
Collaborator

closing as not meeting our https://github.com/0xMiden/protocol?tab=contributing-ov-file#contribution-quality:

[Contributions should:] Be linked to an issue the author has been assigned to

please refrain from opening further PRs unless assigned. We take the liberty to ban contributors not following our contribution guide as this results in overhead for the team. Thanks for your understanding.

@mmagician mmagician closed this May 11, 2026
@AlgofootPrint AlgofootPrint deleted the feat/extend-execution-error-macros branch May 11, 2026 16:47
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.

Extend execution-error assertion macros

2 participants