feat(errorutil): add validation for newly introduced manual error-code allocations - #1080
feat(errorutil): add validation for newly introduced manual error-code allocations#1080SuryanshGarg04 wants to merge 6 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a ChangesError code validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant RootCommand
participant CheckCommand
participant JSONFiles
User->>RootCommand: Execute check with baseline and current paths
RootCommand->>CheckCommand: Run command
CheckCommand->>JSONFiles: Read and unmarshal both files
CheckCommand-->>RootCommand: Return validation error or success
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Signed-off-by: Suryansh Garg <suryanshgarg04@gmail.com>
a52c637 to
e9cbe9e
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/errorutil/internal/coder/check_test.go`:
- Around line 92-103: Update the “Move existing error passes” test case in the
relevant check test so baseline and current ErrOld entries retain the same name
and code but use different Path values, making it an actual path-only move while
preserving the expected no-error result.
In `@cmd/errorutil/internal/coder/commands.go`:
- Line 234: Update the diagnostic in the command validation flow to use Cobra’s
cmd.Printf instead of fmt.Printf, ensuring output respects cmd.SetOut and
remains capturable by callers and tests. Preserve the existing message and
formatting.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fd072f00-8cc4-4755-b0c6-1878c8b9ca83
📒 Files selected for processing (3)
cmd/errorutil/internal/coder/check_test.gocmd/errorutil/internal/coder/commands.gocmd/errorutil/main.go
Signed-off-by: Suryansh Garg <suryanshgarg04@gmail.com>
2f35e38 to
03732e0
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new errorutil check subcommand to validate that newly introduced errors don’t come in with manually assigned numeric codes (enforcing the placeholder-first allocation workflow), and ensures the CLI returns a failing exit status on command errors.
Changes:
- Added
errorutil check <baseline.json> <current.json>to detect newly introduced error names with integer codes. - Updated
cmd/errorutilto exit with status1when command execution fails. - Added tests covering passing/failing scenarios for the new check behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/errorutil/main.go | Ensures non-zero exit status when cobra command execution returns an error. |
| cmd/errorutil/internal/coder/commands.go | Introduces the new check cobra subcommand and wires it into RootCommand(). |
| cmd/errorutil/internal/coder/check_test.go | Adds test coverage for the check command across multiple baseline/current scenarios. |
Signed-off-by: Suryansh Garg <suryanshgarg04@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/errorutil/internal/coder/check_test.go`:
- Around line 150-172: Register cleanup immediately after each successful
os.CreateTemp call in the test, before attempting the next creation or any
writes, so failures trigger cleanup for already-created files. Update the
existing deferred os.Remove calls around bFile and cFile accordingly while
preserving the current file-writing and closing behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: bf74a9a9-9e8a-4fc1-966c-00760537bfbf
📒 Files selected for processing (2)
cmd/errorutil/internal/coder/check_test.gocmd/errorutil/internal/coder/commands.go
🚧 Files skipped from review as they are similar to previous changes (1)
- cmd/errorutil/internal/coder/commands.go
Signed-off-by: Suryansh Garg <suryanshgarg04@gmail.com>
Summary
This PR adds a new
errorutil checkcommand to validate newly introduced error-code allocations.The command compares the analyzed error metadata from a baseline and current codebase, and reports newly introduced errors that already contain manually assigned numeric codes.
This enables downstream CI workflows to enforce the existing placeholder-based allocation workflow before running
errorutil update.Why
The intended workflow for new errors is:
"replace_me").errorutil update.errorutilallocate the next available numeric code.When a contributor manually assigns a numeric code,
errorutil updatetreats it as already allocated and skips it, which can eventually causenext_error_codeto drift and lead to future allocation conflicts.This command provides a reusable validation mechanism to detect those newly introduced manual allocations before they are merged.
What changed
errorutil check <baseline.json> <current.json>Notes
This PR provides the validation capability only.
Repository-specific CI enforcement is implemented separately in:
meshery/meshery#21009
Summary by CodeRabbit
New Features
checkcommand to compare baseline and current error definitions.Bug Fixes
Tests