Skip to content

Commit 8f7c153

Browse files
committed
alpha/declcfg: Include bundle name in version parsing failure message (#811)
Update the alpha/declcfg/declfg_to_model.go package and add the bundle's name while attempting to validate file-based indices that contain an empty or invalid bundle version. Before: ```bash $ ./bin/opm validate index FATA[0000] error parsing bundle version: Version string empty ``` After: ```bash $ ./bin/opm validate index FATA[0000] error parsing bundle operator-1.v0.1.0 version: Version string empty ``` Signed-off-by: timflannagan <[email protected]> Upstream-repository: operator-registry Upstream-commit: 7af20e0f7cae5df6fe79c7804c8d8dff37e63f10
1 parent 67d84fd commit 8f7c153

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

staging/operator-registry/alpha/declcfg/declcfg_to_model.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
9898
}
9999

100100
// Parse version from the package property.
101-
ver, err := semver.Parse(props.Packages[0].Version)
101+
rawVersion := props.Packages[0].Version
102+
ver, err := semver.Parse(rawVersion)
102103
if err != nil {
103-
return nil, fmt.Errorf("error parsing bundle version: %v", err)
104+
return nil, fmt.Errorf("error parsing bundle %q version %q: %v", b.Name, rawVersion, err)
104105
}
105106

106107
channelDefinedEntries[b.Package] = channelDefinedEntries[b.Package].Delete(b.Name)

staging/operator-registry/alpha/declcfg/declcfg_to_model_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestConvertToModel(t *testing.T) {
7777
},
7878
{
7979
name: "Error/BundleInvalidVersion",
80-
assertion: hasError(`error parsing bundle version: Invalid character(s) found in patch number "0.1"`),
80+
assertion: hasError(`error parsing bundle "foo.v0.1.0" version "0.1.0.1": Invalid character(s) found in patch number "0.1"`),
8181
cfg: DeclarativeConfig{
8282
Packages: []Package{newTestPackage("foo", "alpha", svgSmallCircle)},
8383
Bundles: []Bundle{newTestBundle("foo", "0.1.0", func(b *Bundle) {
@@ -87,6 +87,14 @@ func TestConvertToModel(t *testing.T) {
8787
})},
8888
},
8989
},
90+
{
91+
name: "Error/BundleMissingVersion",
92+
assertion: hasError(`error parsing bundle "foo.v" version "": Version string empty`),
93+
cfg: DeclarativeConfig{
94+
Packages: []Package{newTestPackage("foo", "alpha", svgSmallCircle)},
95+
Bundles: []Bundle{newTestBundle("foo", "", func(b *Bundle) {})},
96+
},
97+
},
9098
{
9199
name: "Error/PackageMissingDefaultChannel",
92100
assertion: hasError(`invalid index:

vendor/github.com/operator-framework/operator-registry/alpha/declcfg/declcfg_to_model.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)