Skip to content

Replace errors.Is with IsNotFoundError utility function across handlers and tests for improved readability and consistency. Remove redundant errors imports. - #112

Merged
jlpdeveloper merged 2 commits into
mainfrom
errors-as-type
Jul 19, 2026
Merged

Replace errors.Is with IsNotFoundError utility function across handlers and tests for improved readability and consistency. Remove redundant errors imports.#112
jlpdeveloper merged 2 commits into
mainfrom
errors-as-type

Conversation

@jlpdeveloper

@jlpdeveloper jlpdeveloper commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Description

Code Rabbit Summary

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency when handling missing resources across capability, flow, platform, and product operations.
    • Preserved existing HTTP status codes, error details, validation responses, and server-error handling.
    • Improved recognition of wrapped errors, helping ensure appropriate responses in more scenarios.
  • Tests

    • Added coverage for missing-resource and validation error handling, including wrapped and nil errors.
    • Updated service tests to verify consistent not-found behavior.

Fixes

Closes #

…for `NotFoundError` and `ValidationError`, and add corresponding tests
…ndlers and tests for improved readability and consistency. Remove redundant `errors` imports.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces shared helpers for detecting wrapped not-found and validation errors, migrates HTTP handlers and service tests to use them, and removes obsolete errors.Is test coverage.

Changes

Error classification migration

Layer / File(s) Summary
Error helper contract and coverage
internal/errors.go, internal/errors_test.go, internal/response_test.go
Adds IsNotFoundError and IsValidationError using errors.AsType, removes the prior matching methods, and tests direct, wrapped, nil, unrelated, and formatted errors.
HTTP handler error mapping
internal/capability/handler.go, internal/flow/handler.go, internal/platform/handler.go, internal/product/handler.go
Migrates not-found and validation branches to shared helpers while preserving response mappings and fallback logging.
Service test assertion migration
internal/capability/service_capability_test.go, internal/platform/service_test.go, internal/product/service_test.go
Updates service not-found assertions to use internal.IsNotFoundError.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: chore

Poem

I’m a rabbit with errors tucked neat,
Wrapping old paths in helpers so sweet.
Not-found hops, validation springs,
Tests check the truth of tiny things.
The handlers burrow, responses stay bright—
A tidy code garden by moonlight.

🚥 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 accurately summarizes the main refactor: replacing errors.Is with IsNotFoundError and removing redundant imports across handlers and tests.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch errors-as-type

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.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/capability/service_capability_test.go (1)

161-176: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Fix copy-paste error in test case.

The test case name "Flow Not Found - Empty Name" and its mock setup do not match the expected error "product not found with ID: 999". It appears to be a copy-paste artifact of the preceding test case. Consider updating the test case to actually test a missing flow or empty name, or remove it if redundant. As per path instructions, "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request".

🤖 Prompt for 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.

In `@internal/capability/service_capability_test.go` around lines 161 - 176,
Correct the inconsistent test case around the createCapabilityRequest and
mockCapabilityQuerier setup: either rename and adjust it to cover the intended
missing-flow or empty-name scenario, or remove it if redundant. Ensure the
request, mock behavior, expected error, and test name consistently validate the
same behavior, while preserving coverage for the product-not-found path
elsewhere.

Source: Path instructions

🧹 Nitpick comments (1)
internal/errors_test.go (1)

67-77: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add TestValidationError to complete coverage.

While the unit test code assesses sufficient code coverage for the error helpers, there is no test verifying the Error() output for ValidationError like there is for NotFoundError. Adding it would complete the coverage parity. As per path instructions, "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request".

💡 Proposed optional refactor to add the test
 	t.Run("Error message", func(t *testing.T) {
 		expected := "Product not found with ID: 123"
 		if err.Error() != expected {
 			t.Errorf("expected %q, got %q", expected, err.Error())
 		}
 	})
 
 }
+
+func TestValidationError(t *testing.T) {
+	err := NewValidationErr("invalid input")
+	expected := "invalid input"
+	if err.Error() != expected {
+		t.Errorf("expected %q, got %q", expected, err.Error())
+	}
+}
🤖 Prompt for 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.

In `@internal/errors_test.go` around lines 67 - 77, Add a TestValidationError test
alongside TestNotFoundError in internal/errors_test.go. Construct a
ValidationError with representative input, then assert its Error() output
exactly matches the expected validation-error message, preserving the existing
subtest style.

Source: Path instructions

🤖 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.

Outside diff comments:
In `@internal/capability/service_capability_test.go`:
- Around line 161-176: Correct the inconsistent test case around the
createCapabilityRequest and mockCapabilityQuerier setup: either rename and
adjust it to cover the intended missing-flow or empty-name scenario, or remove
it if redundant. Ensure the request, mock behavior, expected error, and test
name consistently validate the same behavior, while preserving coverage for the
product-not-found path elsewhere.

---

Nitpick comments:
In `@internal/errors_test.go`:
- Around line 67-77: Add a TestValidationError test alongside TestNotFoundError
in internal/errors_test.go. Construct a ValidationError with representative
input, then assert its Error() output exactly matches the expected
validation-error message, preserving the existing subtest style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 160fb5ad-26fa-430e-9f1f-631ec6205c51

📥 Commits

Reviewing files that changed from the base of the PR and between 7503ab3 and 6997c24.

📒 Files selected for processing (10)
  • internal/capability/handler.go
  • internal/capability/service_capability_test.go
  • internal/errors.go
  • internal/errors_test.go
  • internal/flow/handler.go
  • internal/platform/handler.go
  • internal/platform/service_test.go
  • internal/product/handler.go
  • internal/product/service_test.go
  • internal/response_test.go
💤 Files with no reviewable changes (1)
  • internal/response_test.go

@jlpdeveloper
jlpdeveloper merged commit 459d35e into main Jul 19, 2026
3 checks passed
@jlpdeveloper
jlpdeveloper deleted the errors-as-type branch July 19, 2026 00:59
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.

1 participant