Skip to content

Commit

Permalink
Don't Panik!
Browse files Browse the repository at this point in the history
The answer is: 42
  • Loading branch information
hilmarf committed May 2, 2024
1 parent 2d1f934 commit 0593210
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
22 changes: 13 additions & 9 deletions pkg/contexts/ocm/repositories/genericocireg/component.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package genericocireg

import (
Expand Down Expand Up @@ -73,12 +69,12 @@ func (c *componentAccessImpl) GetName() string {

////////////////////////////////////////////////////////////////////////////////

func toTag(v string) string {
func toTag(v string) (string, err) {

Check failure on line 72 in pkg/contexts/ocm/repositories/genericocireg/component.go

View workflow job for this annotation

GitHub Actions / Run tests

undefined: err

Check failure on line 72 in pkg/contexts/ocm/repositories/genericocireg/component.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err

Check failure on line 72 in pkg/contexts/ocm/repositories/genericocireg/component.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err

Check failure on line 72 in pkg/contexts/ocm/repositories/genericocireg/component.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: err

Check failure on line 72 in pkg/contexts/ocm/repositories/genericocireg/component.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: err
_, err := semver.NewVersion(v)
if err != nil {
panic(errors.Wrapf(err, "%s is no semver version", v))
return "", err
}
return strings.ReplaceAll(v, "+", META_SEPARATOR)
return strings.ReplaceAll(v, "+", META_SEPARATOR), nil
}

func toVersion(t string) string {
Expand Down Expand Up @@ -132,7 +128,11 @@ func (c *componentAccessImpl) HasVersion(vers string) (bool, error) {
}

func (c *componentAccessImpl) LookupVersion(version string) (*repocpi.ComponentVersionAccessInfo, error) {
acc, err := c.namespace.GetArtifact(toTag(version))
tag, err := toTag(version)
if err != nil {
return nil, err
}
acc, err := c.namespace.GetArtifact(tag)
if err != nil {
if errors.IsErrNotFound(err) {
return nil, cpi.ErrComponentVersionNotFoundWrap(err, c.name, version)
Expand All @@ -151,7 +151,11 @@ func (c *componentAccessImpl) NewVersion(version string, overrides ...bool) (*re
return nil, accessio.ErrReadOnly
}
override := utils.Optional(overrides...)
acc, err := c.namespace.GetArtifact(toTag(version))
tag, err := toTag(version)
if err != nil {
return nil, err
}
acc, err := c.namespace.GetArtifact(tag)
if err == nil {
if override {
return newComponentVersionAccess(accessobj.ACC_CREATE, c, version, acc, false)
Expand Down
10 changes: 5 additions & 5 deletions pkg/contexts/ocm/repositories/genericocireg/componentversion.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package genericocireg

import (
Expand Down Expand Up @@ -222,7 +218,11 @@ func (c *ComponentVersionContainer) Update() error {
}

logger.Debug("add oci artifact")
if _, err := c.comp.namespace.AddArtifact(c.manifest, toTag(c.version)); err != nil {
tag, err := toTag(version)

Check failure on line 221 in pkg/contexts/ocm/repositories/genericocireg/componentversion.go

View workflow job for this annotation

GitHub Actions / Run tests

undefined: version

Check failure on line 221 in pkg/contexts/ocm/repositories/genericocireg/componentversion.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: version (typecheck)

Check failure on line 221 in pkg/contexts/ocm/repositories/genericocireg/componentversion.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: version) (typecheck)

Check failure on line 221 in pkg/contexts/ocm/repositories/genericocireg/componentversion.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: version) (typecheck)

Check failure on line 221 in pkg/contexts/ocm/repositories/genericocireg/componentversion.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: version
if err != nil {
return err
}
if _, err := c.comp.namespace.AddArtifact(c.manifest, tag); err != nil {
return fmt.Errorf("unable to add artifact: %w", err)
}
}
Expand Down

0 comments on commit 0593210

Please sign in to comment.