Skip to content

Commit

Permalink
Don't Panik! (#758)
Browse files Browse the repository at this point in the history
The answer is: 42

## Description

Populate error to top, if it's not a semver.org conform version.

## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature
- [ ] 🎇 Restructuring
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] 🧑‍💻 Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert

## Related Tickets & Documents

- Closes #756

## Added tests?

- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help
- [ ] Separate ticket for tests # (issue/pr)

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration


## Added to documentation?

- [ ] 📜 README.md
- [ ] 🙅 no documentation needed

## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
hilmarf authored May 2, 2024
1 parent 2d1f934 commit ebe976e
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, error) {
_, 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(c.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 ebe976e

Please sign in to comment.