fix(cli): attach file path and role to SBOM load errors#43
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
When a file passed to the CLI is missing, unreadable, or not valid JSON, main() surfaced the raw low-level error (e.g. "Expected property name or '}' in JSON at position 2") with no indication of which of the two inputs failed or that the SBOM-load step is where it broke. For the tool's headline use case — CI/CD gates — a wrong or corrupt artifact is a common misconfiguration, and the bare message makes it needlessly hard to debug. Introduce loadSbom(path, label), which reads and parses a file and wraps any failure as "Failed to read/parse <old|new> SBOM '<path>': <reason>", distinguishing read failures from parse failures. Valid runs are unaffected. Add tests covering the missing-file, malformed-JSON, and happy paths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JS76safVDXSZwcLRAh8CPv
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
When the CLI is given a file that is missing, unreadable, or not valid JSON,
main()surfaced the raw low-level error with no indication of which of the two inputs failed or that the SBOM-load step is where it broke. For the tool's headline use case — CI/CD gates — a wrong or corrupt artifact is a common misconfiguration, and the bare message makes it needlessly hard to debug.Before
Which file? Was it even the parse step? No way to tell.
After
Changes
loadSbom(path, label)insrc/cli.ts, which reads and parses a file and wraps any failure asFailed to read/parse <old|new> SBOM '<path>': <reason>, distinguishing read failures from parse failures.main()now loads both inputs through it (still in parallel viaPromise.all). Valid runs are unaffected — exit codes and output are unchanged.Scope / conflicts
Touches only the read/parse path in
main()plus a new exported helper and its tests. It does not modifyparseArgs, the parser internals, or the report pipeline, so it composes cleanly with the in-flight CLI/parser PRs. Distinct from #21 (validates recognized-JSON-but-unknown-format input) and #40 (BOM stripping) — this is about attaching file context to read/parse failures.Verification
npm run typecheck,npm run lint, andnpm testall pass; behavior confirmed end-to-end against missing, malformed, and valid inputs.🤖 Generated with Claude Code
https://claude.ai/code/session_01JS76safVDXSZwcLRAh8CPv
Generated by Claude Code