fix: introduce a typed error for repository plugin not found#1967
Conversation
Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new exported error variable Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
bindings/go/credentials/plugins.go (1)
53-55: Consider usingerrors.Newfor sentinel errors and a more specific message.For sentinel errors that don't require formatting and are compared using
errors.Is(),errors.Newis more idiomatic. Additionally, the error message could be more specific to indicate it's a repository plugin.♻️ Suggested improvement
-// ErrNoRepositoryPluginFound is returned when no repository plugin can be found for a given typed object. -// TODO(`@frewilhelm`): Discuss if we want to introduce another API instead, e.g. IsRegistered(typed runtime.Typed) -var ErrNoRepositoryPluginFound = fmt.Errorf("plugin not found") +// ErrNoRepositoryPluginFound is returned when no repository plugin can be found for a given typed object. +// TODO(`@frewilhelm`): Discuss if we want to introduce another API instead, e.g. IsRegistered(typed runtime.Typed) +var ErrNoRepositoryPluginFound = errors.New("no repository plugin found")This would also allow removing the
"fmt"import (line 5) since it's only used for this error declaration.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bindings/go/credentials/plugins.go` around lines 53 - 55, Replace the sentinel error declaration ErrNoRepositoryPluginFound to use errors.New with a more specific message (e.g., "repository plugin not found") instead of fmt.Errorf, update any imports to remove "fmt" and add "errors" if necessary, and keep the existing variable name so callers using errors.Is(ErrNoRepositoryPluginFound, ...) continue to work.bindings/go/credentials/resolve_indirect.go (1)
37-39: Consider including the original error for consistency.When
anyErrisErrNoRepositoryPluginFound, onlyanyErris joined withErrNoIndirectCredentials, but the originalerrfrom line 26 is discarded. For other error cases (line 41), both errors are joined. Consider whether the original error should also be included for debugging/traceability:return nil, errors.Join(err, anyErr, ErrNoIndirectCredentials)If this is intentional (e.g., to provide a cleaner error when both calls fail with the same "not found" reason), the current approach is fine—just wanted to flag the inconsistency.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bindings/go/credentials/resolve_indirect.go` around lines 37 - 39, The branch that handles errors.Is(anyErr, ErrNoRepositoryPluginFound) currently returns errors.Join(anyErr, ErrNoIndirectCredentials) and drops the original err; update that return to include the original err as well (i.e., return errors.Join(err, anyErr, ErrNoIndirectCredentials)) so the stack/traceability is consistent with the other branch that joins both err and anyErr; locate the conditional using anyErr, ErrNoRepositoryPluginFound, ErrNoIndirectCredentials in resolve_indirect.go and modify the return accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@bindings/go/credentials/plugins.go`:
- Around line 53-55: Replace the sentinel error declaration
ErrNoRepositoryPluginFound to use errors.New with a more specific message (e.g.,
"repository plugin not found") instead of fmt.Errorf, update any imports to
remove "fmt" and add "errors" if necessary, and keep the existing variable name
so callers using errors.Is(ErrNoRepositoryPluginFound, ...) continue to work.
In `@bindings/go/credentials/resolve_indirect.go`:
- Around line 37-39: The branch that handles errors.Is(anyErr,
ErrNoRepositoryPluginFound) currently returns errors.Join(anyErr,
ErrNoIndirectCredentials) and drops the original err; update that return to
include the original err as well (i.e., return errors.Join(err, anyErr,
ErrNoIndirectCredentials)) so the stack/traceability is consistent with the
other branch that joins both err and anyErr; locate the conditional using
anyErr, ErrNoRepositoryPluginFound, ErrNoIndirectCredentials in
resolve_indirect.go and modify the return accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b540cfcf-1a14-46b4-a8a7-df9179a5fc8b
📒 Files selected for processing (2)
bindings/go/credentials/plugins.gobindings/go/credentials/resolve_indirect.go
Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com>
…ntials directly (#1970) #1967 introduced a typed error `ErrNoRepositoryPluginFound`. However, functionality wise we do not use that error later on. Thus, we can just use the typed error `ErrNoIndirectCredentials` for now instead. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Refactor** * Improved error handling consistency in the credential resolution process through streamlined error detection logic. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com>
We removed the registration of
AnyConsumerIdentityfor the OCI Credential plugin in #1890. While working on it, we noticed that, now, we error out when no repository plugin is found for a consumer type, e.g.HelmChartRepository, because we do not have a fallback repository anymore.This PR introduces a typed error to handle this. By returning
ErrNoRepositoryPluginFoundthe caller can decide what to do with it. In our case, we do want to append the errorErrNoIndirectCredentialswhen resolving the credential indirectly, so the caller can, for example, just log the error and continue.Currently, we just introduced a typed error. However, we should discuss if we want to add an API, e.g.
IsRegistered(typed runtime.Typed)instead to give potential other users the possibility to use the functionalityThis is a required PR for #1890 because we need to update the
credentialmodule to make it work. You can take a look at the PR to see how the error is used inbindings/go/plugin/manager/registries/credentialrepository/graph_integration.goSummary by CodeRabbit
New Features
Bug Fixes