Skip to content

Improve error handling and panic messages in Rust evaluator#1867

Open
arnaudgelas wants to merge 2 commits intoinformalsystems:mainfrom
arnaudgelas:fix-panic-sites
Open

Improve error handling and panic messages in Rust evaluator#1867
arnaudgelas wants to merge 2 commits intoinformalsystems:mainfrom
arnaudgelas:fix-panic-sites

Conversation

@arnaudgelas
Copy link
Contributor

This commit addresses multiple panic sites in the Rust evaluator to improve debuggability and provide safer alternatives for error handling.

value.rs - New safe accessor methods:

  • Add try_as_int(), try_as_bool(), try_as_str() returning Result<T, QuintError>
  • Add try_as_map(), try_as_list(), try_as_record_map(), try_as_variant()
  • Add type_name() helper for generating informative error messages
  • These provide safe alternatives for callers that need to handle type mismatches gracefully rather than panicking

value.rs - Improved panic messages:

  • All as_* methods now include the actual type name in panic messages (e.g., "Expected integer, got boolean" instead of "Expected integer")
  • cardinality() and contains() panics now show type names
  • Lambda hash/comparison panics now explain that lambdas are not hashable in Quint

builtins.rs - Convert panics to runtime errors:

  • Unknown lazy/eager operators now return QNT500 error instead of panicking
  • This allows better error recovery and more informative error messages
  • getOnlyElement unwrap replaced with documented expect

The existing as_* methods are retained for internal use where type correctness is guaranteed by the type checker, but now provide better debugging information if assumptions are violated.

  • I have read and I understand the Note on AI-assisted contributions
  • Changes manually tested locally and confirmed to work as described
    (including screenshots is helpful)
  • Tests added for any new code
  • Documentation added for any new functionality
  • Entries added to the respective CHANGELOG.md for any new functionality

arnaudgelas and others added 2 commits January 22, 2026 08:26
This commit addresses multiple panic sites in the Rust evaluator to improve
debuggability and provide safer alternatives for error handling.

**value.rs - New safe accessor methods:**
- Add `try_as_int()`, `try_as_bool()`, `try_as_str()` returning `Result<T, QuintError>`
- Add `try_as_map()`, `try_as_list()`, `try_as_record_map()`, `try_as_variant()`
- Add `type_name()` helper for generating informative error messages
- These provide safe alternatives for callers that need to handle type mismatches
  gracefully rather than panicking

**value.rs - Improved panic messages:**
- All `as_*` methods now include the actual type name in panic messages
  (e.g., "Expected integer, got boolean" instead of "Expected integer")
- `cardinality()` and `contains()` panics now show type names
- Lambda hash/comparison panics now explain that lambdas are not hashable in Quint

**builtins.rs - Convert panics to runtime errors:**
- Unknown lazy/eager operators now return QNT500 error instead of panicking
- This allows better error recovery and more informative error messages
- `getOnlyElement` unwrap replaced with documented expect

The existing `as_*` methods are retained for internal use where type correctness
is guaranteed by the type checker, but now provide better debugging information
if assumptions are violated.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

2 participants