Skip to content

Commit 41712d7

Browse files
PRODENG-3148 mcr version detect cleanup (#599)
- go-version no longer throws a runtime error on invalid versions, so we can drop our custom error catch version detection function NOTE What is this: we had issues when we first started analyzing the mcr version in the configuration, as some invalid values would produce a runtime error. The error came right out of hashicorps go-version library, so our only option was to wrap the function and catch any runtime errors. We also included a unit test which validated that a proper error was returned on the invalid version value, to confirm in unit testing that the runtime error was caught Why isn't it needed anymore: I ran the go-version function recently without the wrapper and found that the runtime exception no longer occurs, meaning that our wrapper is no longer needed. The unit test now runs without exception without the wrapper. Signed-off-by: James Nesbitt <[email protected]>
1 parent 83ec222 commit 41712d7

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

pkg/product/common/api/mcr_config.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (c *MCRConfig) Validate() error {
109109
//
110110
// If the channel doesn't contain the right version component then version pinning won't work
111111
func processVersionChannelMatch(config *MCRConfig) error {
112-
ver, vererr := processVersionIsAVersion(config)
112+
ver, vererr := version.NewSemver(config.Version)
113113
if vererr != nil {
114114
return fmt.Errorf("%w; %w", ErrInvalidVersion, vererr)
115115
}
@@ -135,22 +135,3 @@ func processVersionChannelMatch(config *MCRConfig) error {
135135

136136
return nil
137137
}
138-
139-
// go-version.NewVersion throws a runtime error if you pass it something invalid
140-
// so we use, this to provide a runtime safe process for the version parsing.
141-
func processVersionIsAVersion(config *MCRConfig) (ver *version.Version, err error) {
142-
if config.Version == "" {
143-
err = ErrInvalidVersion
144-
return ver, err
145-
}
146-
147-
defer func() {
148-
// recover from panic if one occurred. Set err to nil otherwise.
149-
if recover() != nil {
150-
err = ErrInvalidVersion
151-
}
152-
}()
153-
154-
ver, err = version.NewVersion(config.Version)
155-
return ver, err //nolint:wrapcheck
156-
}

0 commit comments

Comments
 (0)