Skip to content

Fail with error when --profile used without JSON format#1918

Merged
anderseknert merged 2 commits intoopen-policy-agent:mainfrom
mvanhorn:osc/1542-profile-format-error
Mar 29, 2026
Merged

Fail with error when --profile used without JSON format#1918
anderseknert merged 2 commits intoopen-policy-agent:mainfrom
mvanhorn:osc/1542-profile-format-error

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

When --profile is used without --format json, regal now returns an error instead of silently producing no profiling data.

Why this matters

Profiling only works with JSON output. Without this check, users get no feedback when they forget --format json - the command succeeds but profiling data is missing. The error message tells them exactly what to do.

Changes

  • cmd/lint.go: Added validation at the start of lint() that checks params.profile && params.format != formatJSON and returns a descriptive error.

Testing

  • go build ./... passes
  • Manual verification: regal lint --profile . now returns the error message instead of silently dropping profiling data

Fixes #1542

This contribution was developed with AI assistance (Claude Code).

Copy link
Copy Markdown
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

You needed Claude for this? 😮

Check DCO, please. 👇

The --profile flag only works with --format json but previously
produced no output silently when used with other formats. Now
returns an error telling the user to use --format json.

Fixes open-policy-agent#1542

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Replace fmt.Errorf with errors.New (no format verbs) and add
blank line above ctx assignment per wsl_v5 linter.

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
@mvanhorn mvanhorn force-pushed the osc/1542-profile-format-error branch from 9f19c8c to 1baf26b Compare March 27, 2026 18:35
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Fair point - this was definitely not Claude's finest hour. DCO and lint fixed in 1baf26b.

@anderseknert anderseknert added this pull request to the merge queue Mar 28, 2026
@anderseknert
Copy link
Copy Markdown
Member

Thanks 👍

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 28, 2026
@anderseknert anderseknert added this pull request to the merge queue Mar 29, 2026
Merged via the queue into open-policy-agent:main with commit 02a9dc8 Mar 29, 2026
8 checks passed
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Thanks for the review and merge!

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.

Have regal lint --profile show an error message if not --format json is set

3 participants