Skip to content

Label native crashes by type instead of always 'Stack overflow!'#78

Merged
CoreyRDean merged 3 commits into
developfrom
fix/setranslator-exception-labels
May 30, 2026
Merged

Label native crashes by type instead of always 'Stack overflow!'#78
CoreyRDean merged 3 commits into
developfrom
fix/setranslator-exception-labels

Conversation

@CoreyRDean
Copy link
Copy Markdown
Collaborator

Non-technical summary

When a compiled Blitz program hits a CPU-level fault — a divide-by-zero, a Null/dangling object access, an illegal instruction, or a real stack overflow — BlitzForge is supposed to tell you which one. A switch-statement bug meant every such crash was reported as "Stack overflow!", including the most common one (touching a Null object). That actively misdirects debugging. This PR makes each fault report its true cause. Advances INTENT #6 ("trust the runtime… instrumented enough to diagnose").

Technical summary

seTranslator in src/blitzrc/bbruntime_dll/bbruntime_dll.cpp (the Windows _set_se_translator handler) had a switch over exception codes with no break statements — so panicStr always fell through to the final case, "Stack overflow!". Added break; after each case. Minimal correctness fix; no new codes, no change to the panic/bbEx/block-trace pipeline. Windows-only by nature; macOS has its own signal path (out of scope).

Verified: a runtime integer divide-by-zero now reports Error: Integer divide by zero (was Error: Stack overflow!). In -t test mode the panic message reaches stdout via the DummyDebugger, so it's capturable.

Acceptance criteria + results

  • A runtime integer divide-by-zero reports "Integer divide by zero", not "Stack overflow!" — verified against the rebuilt binary.
  • Unknown codes still report "Unknown runtime exception" (default unchanged).
  • Pinned by a CLI-contract check: test.bat (:expect_failure … "Integer divide by zero") + test.sh parity, run against scripts/fixtures/divzero.bb — a deliberate crash fixture placed outside tests/ (it panics + exit(1) by design, so it must not run in the -t suite loop) and outside the corpus-sweep dirs.
  • Full test.bat green; build 0 errors; corpus sweep unaffected.

Trade-offs, deferred follow-ups

  • Skipped adding more exception codes (FLT_DIVIDE_BY_ZERO, PRIV_INSTRUCTION) — scope creep beyond the missing-break bug.
  • A normal Test block can't assert this (the panic exit(1)s mid-run), hence the standalone-fixture CLI contract.
  • Deferred (high priority — a doc-correctness defect from PR Document BlitzForge's modern language features + fix the Keywords reference #67): help/language/lang_ref_modern.html cites tests/GarbageCollectionTest.bb as evidence for the "reference cycles leak — break them yourself" contract, but that test has no cycle case. A recon pitch this iteration proposed a GC acceptance suite that would both pin the contract and make the citation true; worth doing soon.
  • Contextual-keyword Phase 2 (Release + expression-position keywords).

🤖 Generated with Claude Code

CoreyRDean and others added 3 commits May 30, 2026 00:51
seTranslator (bbruntime_dll.cpp), the Windows structured-exception translator,
had a switch with no `break` statements, so every CPU fault fell through to the
last case: a divide-by-zero, a null/dangling object access violation, and an
illegal instruction were ALL reported to the user as "Stack overflow!". The
mislabel sends anyone debugging (most commonly) a Null-object access down a
stack-overflow rabbit hole. Contradicts INTENT #6 ("trust the runtime …
instrumented enough to diagnose").

Add `break;` after each case so each exception code maps to its own message.
Minimal correctness fix -- no new codes, no pipeline change. Windows-only by
nature (_set_se_translator); macOS has its own signal path.

Verified: a runtime integer divide-by-zero now reports "Integer divide by zero"
(was "Stack overflow!"). In -t mode the panic message reaches stdout via the
DummyDebugger, so it is capturable; scripts/fixtures/divzero.bb is the deliberate
crash fixture used by the test harness (it panics + exits non-zero by design, so
it lives outside tests/ and the corpus sweep).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
test.bat asserts a runtime divide-by-zero is labeled "Integer divide by zero"
(not "Stack overflow!") via :expect_failure against scripts/fixtures/divzero.bb.
test.sh adds the parity check, guarded so it only flags the regression where the
structured-exception message actually appears (no-op on the compile-only macOS path).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Root cause (switch fall-through), the -t stdout verification path, and deferred
follow-ups (the GC doc false-citation from #67; contextual-keyword Phase 2).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@CoreyRDean CoreyRDean requested a review from a team as a code owner May 30, 2026 05:53
@CoreyRDean CoreyRDean added the bug Something isn't working label May 30, 2026
@CoreyRDean CoreyRDean merged commit 4cec8cb into develop May 30, 2026
4 checks passed
@CoreyRDean CoreyRDean deleted the fix/setranslator-exception-labels branch May 30, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant