Skip to content

fix: surface the real error when namespace caching fails#4656

Open
ogulcanaydogan wants to merge 1 commit into
open-policy-agent:masterfrom
ogulcanaydogan:fix/ns-cache-error-message
Open

fix: surface the real error when namespace caching fails#4656
ogulcanaydogan wants to merge 1 commit into
open-policy-agent:masterfrom
ogulcanaydogan:fix/ns-cache-error-message

Conversation

@ogulcanaydogan

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

toNamespace returns (nil, err) when the unstructured-to-Namespace conversion fails, but the error in nsCache.Add formatted ns (which is always nil on that path) instead of err. As a result the wrapped error read cannot cache Namespace: <nil> and the actual conversion failure reason was discarded.

This formats err instead so the real reason surfaces. One-line diagnostic fix, no behavior change.

Which issue(s) this PR fixes

None; found while reading the target caching code.

Special notes for your reviewer

go test ./pkg/target/... passes. The message is not asserted by any existing test.

toNamespace returns (nil, err) on conversion failure, but the error
message formatted ns (always nil here) instead of err, so the log read
"cannot cache Namespace: <nil>" and discarded the actual reason. Format
err instead.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@gmail.com>
@ogulcanaydogan ogulcanaydogan requested a review from a team as a code owner July 4, 2026 21:53
Copilot AI review requested due to automatic review settings July 4, 2026 21:53
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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

This PR fixes an incorrect format argument in the namespace cache's error path. In nsCache.Add, when toNamespace fails the conversion, it returns (nil, err). The wrapped error message previously formatted ns (always nil on that path), producing cannot cache Namespace: <nil> and discarding the real conversion failure reason. The fix formats err instead, so the actual cause is surfaced. This aids diagnosing malformed Namespace objects flowing through the target caching path without changing behavior.

Changes:

  • Format the conversion err rather than the always-nil ns value in the wrapped ErrCachingType error.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.84%. Comparing base (3350319) to head (08362d8).
⚠️ Report is 770 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (3350319) and HEAD (08362d8). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (3350319) HEAD (08362d8)
unittests 2 1
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4656      +/-   ##
==========================================
- Coverage   54.49%   44.84%   -9.66%     
==========================================
  Files         134      284     +150     
  Lines       12329    21041    +8712     
==========================================
+ Hits         6719     9435    +2716     
- Misses       5116    10798    +5682     
- Partials      494      808     +314     
Flag Coverage Δ
unittests 44.84% <100.00%> (-9.66%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

3 participants