Skip to content

Commit 00100ff

Browse files
matthiasbrunsdependabot[bot]morri-songithub-actions[bot]souleb
authored
fix(1560): add more explicit errors on get cv (#1787)
On-behalf-of: SAP <[email protected]> <!-- markdownlint-disable MD041 --> #### What this PR does / why we need it Users complain about confusing error messages in `get cv`. Errors that are related to technical problems, like missing docker binaries or other things, are not properly communicated and hidden by a generic `invalid component reference` message. This PR logs more details in case of technical errors. #### Which issue(s) this PR is related to Fixes: #1560 --------- Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Matthias Bruns <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gerald Morrison <[email protected]> Co-authored-by: GitHub Actions Bot <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: souleb <[email protected]> Co-authored-by: Uwe Krueger <[email protected]>
1 parent e98265f commit 00100ff

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ format:
8989
check: ## Run golangci-lint.
9090
go tool golangci-lint run --timeout 10m --config .github/config/golangci.yaml $(EFFECTIVE_DIRECTORIES)
9191

92+
.PHONY: check-fix
93+
check-fix: ## Run golangci-lint.
94+
go tool golangci-lint run --fix --timeout 10m --config .github/config/golangci.yaml $(EFFECTIVE_DIRECTORIES)
95+
9296
.PHONY: force-test
9397
force-test:
9498
@go test -vet=off --count=1 $(EFFECTIVE_DIRECTORIES)

api/credentials/internal/utils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ func CredentialsForConsumer(ctx ContextProvider, id ConsumerIdentity, unknownAsE
1919
}
2020
creds, err := src.Credentials(cctx)
2121
if err != nil {
22-
return nil, errors.Wrapf(err, "lookup credentials failed for %s", id)
22+
unknownErr := errors.ErrUnknown(KIND_CREDENTIALS, id.String())
23+
err = errors.Wrapf(err, "unable to receive credentials for %s", id)
24+
return nil, errors.Wrap(unknownErr, err)
2325
}
2426
return creds, nil
2527
}

cmds/ocm/commands/ocmcmds/common/handlers/comphdlr/typehandler.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/mandelsoft/goutils/errors"
1010

1111
clictx "ocm.software/ocm/api/cli"
12+
"ocm.software/ocm/api/credentials"
1213
"ocm.software/ocm/api/ocm"
1314
"ocm.software/ocm/api/ocm/compdesc"
1415
metav1 "ocm.software/ocm/api/ocm/compdesc/meta/v1"
@@ -159,12 +160,19 @@ func (h *TypeHandler) get(repo ocm.Repository, elemspec utils.ElemSpec) ([]outpu
159160
if err != nil {
160161
evaluated = nil
161162
if h.resolver != nil {
163+
if errors.IsErrUnknownKind(err, credentials.KIND_CREDENTIALS) {
164+
return nil, errors.Wrapf(err, "failed to get component version %q", name)
165+
}
166+
167+
origErr := err
162168
comp, err := ocm.ParseComp(name)
163169
if err != nil {
170+
err = errors.Wrap(origErr, err)
164171
return nil, errors.Wrapf(err, "invalid component version reference %q", name)
165172
}
166173
if comp.IsVersion() {
167174
cv, err := h.resolver.LookupComponentVersion(comp.Component, *comp.Version)
175+
err = errors.Wrap(origErr, err)
168176
if err != nil {
169177
return nil, err
170178
}
@@ -174,7 +182,7 @@ func (h *TypeHandler) get(repo ocm.Repository, elemspec utils.ElemSpec) ([]outpu
174182
evaluated.Ref.CompSpec = comp
175183
evaluated.Version = cv
176184
evaluated.Repository = cv.Repository()
177-
h.session.Closer(cv)
185+
_, _ = h.session.Closer(cv)
178186
}
179187
}
180188
}

0 commit comments

Comments
 (0)