Skip to content

fix: load YAML reports in diff --report - #1769

Merged
egibs merged 2 commits into
chainguard-dev:mainfrom
RaphaelFakhri:fix/diff-report-yaml
Oct 27, 2026
Merged

egibs merged 2 commits into
chainguard-dev:mainfrom
RaphaelFakhri:fix/diff-report-yaml

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

mal diff --report failed on reports written with --format yaml:

$ mal diff --report a.yaml b.yaml
💣 load source report: invalid character 'i' in literal false (expecting 'a')

report.Load only parsed JSON, although the --report feature and the comment in action.Diff say JSON and YAML reports are supported.

Changes

  • report.Load still tries JSON first. If that fails and the input is not empty and does not start with {, it reads the input as YAML, which the YAML renderer writes with its file reports under files.
  • Input that is neither, such as plain text, an empty file, or YAML without files, still returns the JSON error, so TestDiffReportErrors and the existing TestLoad cases are unchanged.
  • malcontent.ScanResult is unchanged; the YAML key is read through a local struct in Load.

Testing

  • TestLoadYAML loads a report in the YAML renderer's shape and checks that non-report YAML still fails.
  • TestDiffYAMLReports writes both reports with the real YAML renderer and checks the removed, added, and modified keys.
  • Both tests fail without the change (invalid character 'i' in literal false) and pass with it.
  • go test -race ./pkg/... ./cmd/... passes, and make golangci-lint-lint reports 0 issues.
  • End to end, mal diff --report on YAML reports of two directories produces output byte-identical to the same diff on the JSON reports, in both the terminal and JSON renderers.

Fixes #1768

report.Load only parsed JSON, so diffing two reports written with
--format yaml failed with "invalid character 'i' in literal false".
Input that does not parse as JSON and is not a JSON object is now read
as YAML, which the YAML renderer writes with its file reports under
"files". Input that is neither keeps the JSON error.

@egibs egibs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread pkg/report/load.go
if trimmed := bytes.TrimSpace(data); len(trimmed) == 0 || trimmed[0] == '{' {
return report, err
}
var yr struct {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ScanResult's yaml:"Files" tag is unused elsewhere; changing it to files would drop this struct.

@egibs
egibs merged commit 37cc825 into chainguard-dev:main Oct 27, 2026
17 checks passed
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.

mal diff --report fails on YAML reports

2 participants