Skip to content

feat: harden BDD target stderr error handler to exit on ERROR severity#404

Merged
DavidCozens merged 2 commits into
mainfrom
feat/bdd-target-fatal-exit-on-error
May 19, 2026
Merged

feat: harden BDD target stderr error handler to exit on ERROR severity#404
DavidCozens merged 2 commits into
mainfrom
feat/bdd-target-fatal-exit-on-error

Conversation

@DavidCozens

@DavidCozens DavidCozens commented May 19, 2026

Copy link
Copy Markdown
Owner

Purpose

S11.05 part B (#403) finished green but spent 23 minutes in CI vs the usual 4–5. Per-step timing showed both build-linux-tunable-override and build-freertos-target spent ~16 minutes in the "Initialize containers" step (ghcr.io image pull) — runner cold-cache, not a project regression. Other jobs on the same run using the same image pulled in seconds.

The real concern surfaced by that diagnosis is that pool exhaustion in a BDD wiring scenario would currently fail silently: _Create returns the shared null object, the BDD target keeps running on it, the oracle receives nothing, the scenario times out, and the captured failure is "oracle received 0 of 1" rather than "BDD target died on POOL_EXHAUSTED". Same failure class as part A's STREAM_SENDER default-1 bust (#402).

This PR hardens the BDD-target stderr handler so the silent-drop class becomes a loud, locally-debuggable failure.

Change Description

Bdd/Targets/Common/BddTargetStderrErrorHandler.c now branches on severity:

  • severity <= SOLIDSYSLOG_SEVERITY_ERROR (EMERGENCY / ALERT / CRITICAL / ERROR) ⇒ fprintf(stderr, "BDD-TARGET: FATAL: %s\n", message), fflush(stderr), _Exit(3).
  • Any other severity (WARNING, etc.) ⇒ existing print-only line, unchanged.

Design notes:

  • _Exit (C99 <stdlib.h>) not _exit (POSIX <unistd.h>). The Common/ file is shared by the Windows BDD target as well, so the portable C99 form is required. Same no-atexit / no-stdio-flush semantics — fflush(stderr) is called first so the FATAL marker reaches the wire before the process disappears.
  • <= rather than == so EMERGENCY / ALERT / CRITICAL also exit. Library code only emits ERROR/WARNING today, so the forms are equivalent in practice, but <= is the defensible semantics.
  • No unit test. The handler is six production lines; a _Exit seam (function-pointer indirection + paired interceptor test) is more abstraction than the change justifies. The honest validation is end-to-end via a BDD scenario that deliberately starves a pool — which doesn't yet exist; raised as a Deferred item in DEVLOG. Compile-time gates carry the rest.

Test Evidence

All local gates green on the branch in the project's dev containers:

  • debug — 1188 tests pass
  • sanitize (ASan + UBSan) — 1188 tests pass
  • clang-debug — 1188 tests pass
  • tidy — clean (warnings-as-errors)
  • cppcheck — clean
  • coverage — clean
  • iwyu — clean (invoked as cmake --build --preset iwyu --target iwyu)
  • clang-format --dry-run --Werror over Core/Interface Core/Source Tests Bdd/Targets — clean

CI will cover Windows MSVC, FreeRTOS cross/QEMU, and the BDD jobs.

Areas Affected

  • Bdd/Targets/Common/BddTargetStderrErrorHandler.c — Tier 3 (BDD targets, best-effort). No production-library impact.
  • DEVLOG.md — session entry.

No public-header or Core/ changes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling to treat critical error severities as fatal, triggering process termination with a clear status message for improved system robustness.
  • Documentation

    • Added documentation detailing error handling hardening improvements and related design decisions.

Review Change Stack

ERROR-class severities (EMERGENCY/ALERT/CRITICAL/ERROR) write
'BDD-TARGET: FATAL: <message>\n', flush stderr, and _Exit(3).
WARNING stays as the existing print-only line.

Turns silent NULL-fallback-on-pool-exhaustion into a loud,
debuggable BDD failure ('BDD target died' vs. 'oracle received
0 of 1').
@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bbf791b2-ab41-4481-96df-e1215a2ff897

📥 Commits

Reviewing files that changed from the base of the PR and between 1a79af9 and c637a5d.

📒 Files selected for processing (2)
  • Bdd/Targets/Common/BddTargetStderrErrorHandler.c
  • DEVLOG.md

📝 Walkthrough

Walkthrough

The PR hardens the BDD target stderr error handler to treat SOLIDSYSLOG_SEVERITY_ERROR and below as fatal. When such severities are logged, the handler now prints a BDD-TARGET: FATAL marker, flushes stderr, and terminates the process via _Exit(3). Higher severities continue to log without exiting. A new <stdlib.h> include and devlog entry document the change.

Changes

BDD stderr handler fatal exit hardening

Layer / File(s) Summary
Stderr handler fatal exit implementation and documentation
Bdd/Targets/Common/BddTargetStderrErrorHandler.c, DEVLOG.md
StderrErrorHandler adds severity-based branching: severities at or below SOLIDSYSLOG_SEVERITY_ERROR trigger a BDD-TARGET: FATAL message, stderr flush, and process termination via _Exit(3). Higher severities log without exiting. The <stdlib.h> include is added for _Exit, and the change is documented in the devlog with implementation details and deferred questions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A fatal exit hops so clean,
When errors reach the danger scene,
ERROR down means _Exit time,
No mercy for severity's climb!
BDD-TARGET logs its last goodbye. 🌙

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: hardening the BDD target stderr handler to exit on ERROR severity.
Description check ✅ Passed The description is comprehensive and follows the template structure, covering Purpose, Change Description, Test Evidence, and Areas Affected with substantial detail.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/bdd-target-fatal-exit-on-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

☀️   Quality Summary

   🚦   build-linux-gcc: 100% successful (✔️ 1192 passed, 🙈 2 skipped)
   🚦   build-freertos-host-tdd: 100% successful (✔️ 1312 passed, 🙈 2 skipped)
   🚦   build-linux-clang: 100% successful (✔️ 1144 passed, 🙈 2 skipped)
   🚦   sanitize-linux-gcc: 100% successful (✔️ 1144 passed, 🙈 2 skipped)
   🚦   integration-linux-openssl: 100% successful (✔️ 9 passed)
   🚦   integration-windows-openssl: 100% successful (✔️ 9 passed)
   🚦   bdd-linux-syslog-ng: 94% successful (✔️ 46 passed, 🙈 3 skipped)
   🚦   bdd-windows-otel: 90% successful (✔️ 44 passed, 🙈 5 skipped)
   🚦   bdd-freertos-qemu: 73% successful (✔️ 36 passed, 🙈 13 skipped)
   🚦   build-windows-msvc: 100% successful (✔️ 1045 passed, 🙈 1 skipped)
   🚦   build-linux-tunable-override: 100% successful (✔️ 1144 passed, 🙈 2 skipped)
   ⚠️   Clang-Tidy: 6 warnings (normal: 6)
   ⚠️   CPPCheck: No warnings


Created by Quality Monitor v1.14.0 (#f3859fd). More details are shown in the GitHub Checks Result.

@DavidCozens DavidCozens merged commit 65c03e8 into main May 19, 2026
20 checks passed
@DavidCozens DavidCozens deleted the feat/bdd-target-fatal-exit-on-error branch May 19, 2026 19:45
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.

1 participant