builtins: route assert failures through g_has_error instead of exit(1) - #220
Merged
Conversation
builtin_assert called exit(1) on failure, bypassing main's teardown (env_decref, gc_collect_at_exit, chunk_free). Standalone leaker test_assert_fail.eigs leaked the global env and every registered builtin (~25 KB, 198 objects). Setting g_has_error + g_error_msg and returning null lets CHECK_ERROR unwind vm_run to main, which runs the standard teardown and exits non-zero from g_has_error. Same stderr output, same exit code, no leak. Side effect: assert failures are now catchable by try/catch, matching throw. Previously exit(1) was uncatchable. Standalone leaker count: 13 -> 12. Suite 1882/1882. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 tasks
InauguralPhysicist
added a commit
that referenced
this pull request
Jun 17, 2026
- CHANGELOG [Unreleased]: document #220 behavior change (assert failures route through g_has_error and are catchable by try/catch; exit code + stderr unchanged for uncaught failures). - docs/BUILTINS.md: assert row no longer says "Exit with message"; now describes the catchable runtime error. - CLAUDE.md: harness leak tally reflects the actual current count (10, down from 13 after PRs #212/#213/#214/#220) and the suite size is bumped to ~1882 to match. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
builtin_assertcalledexit(1)on failure, skipping main's teardown (env_decref,gc_collect_at_exit,chunk_free). Standalone leakertest_assert_fail.eigsleaked the global env and every registered builtin — ~25 KB / 198 objects.exit(1)forg_has_error = 1+g_error_msgsnprintf +make_null().CHECK_ERRORin vm_run unwinds to main, which runs the normal teardown and returns non-zero becauseg_has_erroris set.ASSERT FAIL: <msg>) and exit code (1) preserved.Side effect
assertfailures are now catchable bytry/catch, matchingthrow. Previouslyexit(1)was uncatchable.Numbers
Test plan
make asan && tests/test_assert_fail.eigsis leak-clean, exit 1, same stderr.make asan && bash tests/run_all_tests.sh— 1882/1882, harness leak tally unchanged at 10.test_assert_fail.eigs).🤖 Generated with Claude Code