Skip to content

Reduce panic-driven internal control flow#6

Merged
AlexandreYang merged 2 commits intomainfrom
dd/reduce-panic-internal-control-flow
Mar 9, 2026
Merged

Reduce panic-driven internal control flow#6
AlexandreYang merged 2 commits intomainfrom
dd/reduce-panic-internal-control-flow

Conversation

@AlexandreYang
Copy link
Copy Markdown
Member

Summary

Converts internal panics in hot paths to explicit fatal errors, reserving panics for truly unrecoverable conditions (public API misuse, user handler crashes).

Changes

  • interp/vars.go: Added internalErrorf helper that records assertion failures via exit.fatal instead of panicking. Converted panics in lookupVar, setVarWithIndex, and assignVal to use it.
  • interp/api.go: Converted Reset() panic for zero-value Runner to exit.fatal + early return. Added explicit fatal-error check in Run() after Reset() so the error surfaces without relying on the recover wrapper.
  • interp/handler.go: Kept HandlerCtx panic (public API, genuine programmer error) but clarified the doc comment.
  • interp/allowed_paths_internal_test.go: Added TestRunZeroValueRunnerReturnsError to verify the new explicit error path.

The recover() in Run() is retained as a safety net for panics from user-provided handlers (validated by existing TestRunRecoversPanic).

Testing

  • All existing tests pass (go test ./...)
  • New test verifies zero-value Runner returns an explicit error instead of panicking

PR by Bits
View session in Datadog

Comment @DataDog to request changes

Co-authored-by: AlexandreYang <49917914+AlexandreYang@users.noreply.github.com>
@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 Bot commented Mar 9, 2026

View session in Datadog

Bits Dev status: ✅ Done

CI Auto-fix: Disabled | Enable

Comment @DataDog to request changes

Co-authored-by: AlexandreYang <49917914+AlexandreYang@users.noreply.github.com>
@AlexandreYang AlexandreYang merged commit f2dee7a into main Mar 9, 2026
7 checks passed
@AlexandreYang AlexandreYang deleted the dd/reduce-panic-internal-control-flow branch March 9, 2026 09: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.

2 participants