Skip to content

feat(errorutil): add validation for newly introduced manual error-code allocations - #1080

Open
SuryanshGarg04 wants to merge 6 commits into
meshery:masterfrom
SuryanshGarg04:feat/errorutil-check-new-codes
Open

feat(errorutil): add validation for newly introduced manual error-code allocations#1080
SuryanshGarg04 wants to merge 6 commits into
meshery:masterfrom
SuryanshGarg04:feat/errorutil-check-new-codes

Conversation

@SuryanshGarg04

@SuryanshGarg04 SuryanshGarg04 commented Jul 29, 2026

Copy link
Copy Markdown

Summary

This PR adds a new errorutil check command 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:

  1. Introduce the error using a non-numeric placeholder (for example, "replace_me").
  2. Run errorutil update.
  3. Let errorutil allocate the next available numeric code.

When a contributor manually assigns a numeric code, errorutil update treats it as already allocated and skips it, which can eventually cause next_error_code to 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

  • Added errorutil check <baseline.json> <current.json>
  • Detect newly introduced errors that already contain numeric codes
  • Return a non-zero exit status when validation fails
  • Added tests covering valid and invalid allocation scenarios

Notes

This PR provides the validation capability only.

Repository-specific CI enforcement is implemented separately in:

meshery/meshery#21009

Summary by CodeRabbit

  • New Features

    • Added a CLI check command to compare baseline and current error definitions.
    • Flags newly introduced or reused manual error codes and requires placeholders for new entries.
  • Bug Fixes

    • The CLI now exits with a failure status when a command encounters an error.
  • Tests

    • Added coverage for valid and invalid additions, code reuse, renames, moves, and mixed changes.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a check CLI subcommand that compares baseline and current error definitions, rejects newly assigned codes, registers the command, tests its scenarios, and exits with status 1 when command execution fails.

Changes

Error code validation

Layer / File(s) Summary
Check command and validation coverage
cmd/errorutil/internal/coder/commands.go, cmd/errorutil/internal/coder/check_test.go
The check command compares error names between JSON files and rejects new entries with integer-assigned codes. Table-driven tests cover accepted and rejected changes.
CLI failure propagation
cmd/errorutil/main.go
The executable now exits with status 1 when the root command returns an error.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the new validation for manually assigned error codes, which is the primary change in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: Suryansh Garg <suryanshgarg04@gmail.com>
@SuryanshGarg04
SuryanshGarg04 force-pushed the feat/errorutil-check-new-codes branch from a52c637 to e9cbe9e Compare July 29, 2026 19:56
@SuryanshGarg04 SuryanshGarg04 changed the title feat(errorutil): enforce placeholder error allocation via check command feat(errorutil): add validation for newly introduced manual error-code allocations Jul 29, 2026
@SuryanshGarg04
SuryanshGarg04 marked this pull request as ready for review July 29, 2026 20:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6f8803d and e9cbe9e.

📒 Files selected for processing (3)
  • cmd/errorutil/internal/coder/check_test.go
  • cmd/errorutil/internal/coder/commands.go
  • cmd/errorutil/main.go

Comment thread cmd/errorutil/internal/coder/check_test.go
Comment thread cmd/errorutil/internal/coder/commands.go Outdated
Signed-off-by: Suryansh Garg <suryanshgarg04@gmail.com>
@SuryanshGarg04
SuryanshGarg04 force-pushed the feat/errorutil-check-new-codes branch from 2f35e38 to 03732e0 Compare July 29, 2026 20:22
Copilot AI lite review requested due to automatic review settings August 4, 2026 08:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/errorutil to exit with status 1 when 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.

Comment thread cmd/errorutil/internal/coder/commands.go Outdated
Comment thread cmd/errorutil/internal/coder/check_test.go Outdated
Signed-off-by: Suryansh Garg <suryanshgarg04@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 840fe69 and 9339e05.

📒 Files selected for processing (2)
  • cmd/errorutil/internal/coder/check_test.go
  • cmd/errorutil/internal/coder/commands.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/errorutil/internal/coder/commands.go

Comment thread cmd/errorutil/internal/coder/check_test.go Outdated
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.

2 participants