Skip to content

add --diagnostics json flag for structured error output#293

Merged
cs01 merged 2 commits intomainfrom
json-diagnostics-flag
Mar 12, 2026
Merged

add --diagnostics json flag for structured error output#293
cs01 merged 2 commits intomainfrom
json-diagnostics-flag

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 12, 2026

Summary

  • Adds --diagnostics json flag to build, run, and ir commands
  • On success: outputs {"diagnostics":[],"success":true} to stdout
  • On error: outputs {"diagnostics":[{"severity":"error","message":"..."}],"success":false} to stdout
  • Normal mode (no flag) is completely unchanged
  • Enables reliable agent/tooling integration without regex-parsing error messages

Implementation

  • Flag added to both chad-node.ts and chad-native.ts CLI entry points
  • In JSON mode, stderr is intercepted during compilation so all error paths (semantic analysis, codegen, semantic passes, parser) produce structured JSON on stdout
  • No changes to any files compiled by the native compiler (avoids self-hosting breakage) — only compiler.ts, chad-node.ts, chad-native.ts, and a no-op stub in native-compiler-lib.ts

Test plan

  • verify:quick passes (tests + Stage 1 self-hosting)
  • Success case: chad build hello.ts --diagnostics json{"diagnostics":[],"success":true}
  • Closure mutation error: structured JSON with error message
  • Parser error (object spread): structured JSON with error message
  • Normal mode (no flag): output unchanged

🤖 Generated with Claude Code

@cs01 cs01 merged commit 45f3c42 into main Mar 12, 2026
12 checks passed
@cs01 cs01 deleted the json-diagnostics-flag branch March 19, 2026 05:23
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