Audit: Replace panics with Result returns #132
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#132
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Audit all builtins and runtime functions to replace panics with proper Result/error returns. Errors should be values, not crashes.
Background
During the design discussion for Weaves (#131), we identified that several existing builtins use Rust panics for error conditions that should be recoverable:
Known Issues
Channel operations
chan.receive- panics on closed channelchan.send- panics on closed channel-safevariants exist (chan.send-safe,chan.receive-safe) but the naming is backwardsNaming convention problem
The current
-safesuffix implies the default is unsafe. This is backwards:chan.receive(panics) vschan.receive-safe(returns Result)chan.receive(returns Result) vschan.receive!orchan.receive-unchecked(panics for perf-critical code)Proposed Changes
builtins.rsand their runtime implementations-safesuffix - make safe the default-unchecked!suffix for explicit "I know what I'm doing" variants that skip checks for performanceResult Pattern
Seq already has
std:resultwith proper Result/Option handling:Audit Checklist
chan.send/chan.receivevariant.field-at(out of bounds)list.map/list.filter/list.fold(quotation errors)Non-Goals
Some panics are appropriate and should remain:
The distinction: user errors (bad input, closed channel, file not found) should return Results. Runtime bugs (impossible states, invariant violations) can panic.
final fix https://github.com/navicore/patch-seq/pull/137