fix: preserve mainArtifact default on parse failure in import and import-url#460
Open
AdeshDeshmukh wants to merge 1 commit into
Open
fix: preserve mainArtifact default on parse failure in import and import-url#460AdeshDeshmukh wants to merge 1 commit into
AdeshDeshmukh wants to merge 1 commit into
Conversation
…ort-url Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves handling of the optional mainArtifact boolean flag in import commands by avoiding unintended value changes when boolean parsing fails.
Changes:
- Prevent
mainArtifactfrom being overwritten whenstrconv.ParseBoolreturns an error. - Replace raw error printing with a clearer parse-failure message.
- Refactor parsing in
cmd/import.goto use a scopedparseErrvariable and only assign on success.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/importURL.go | Avoids assigning mainArtifact on parse failure and emits a clearer message. |
| cmd/import.go | Refactors bool parsing to only apply parsed values on success and keep defaults on failure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
109
to
114
| val, err := strconv.ParseBool(urlAndMainAtrifactAndSecretName[2]) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| fmt.Printf("Cannot parse '%s' as Bool, default to true\n", urlAndMainAtrifactAndSecretName[2]) | ||
| } else { | ||
| mainArtifact = val | ||
| } |
Comment on lines
124
to
132
| if strings.Contains(f, ":") { | ||
| pathAndMainArtifact := strings.Split(f, ":") | ||
| f = pathAndMainArtifact[0] | ||
| mainArtifact, err = strconv.ParseBool(pathAndMainArtifact[1]) | ||
| if err != nil { | ||
| if val, parseErr := strconv.ParseBool(pathAndMainArtifact[1]); parseErr != nil { | ||
| fmt.Printf("Cannot parse '%s' as Bool, default to true\n", pathAndMainArtifact[1]) | ||
| } else { | ||
| mainArtifact = val | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both the
importandimport-urlcommands accept a:trueor:falsesuffix to mark an artifact as primary or secondary. If that suffix is malformed (e.g.:truor:xyz),strconv.ParseBoolreturnsfalseas its zero value — and thatfalsewas being unconditionally assigned tomainArtifact, silently overriding the intended default oftrue.In practice this means a typo in the boolean flag would cause Microcks to treat the artifact as secondary when the user almost certainly meant it as primary. No clear error, just wrong behavior.
The fix is the same in both files: only assign
mainArtifactwhenParseBoolsucceeds. On failure, print a clear warning and keep the default value oftrue.Files changed:
cmd/import.go— replaced the outervar err error+ direct assignment with a scopedvalvariable inside an if/else block. ThemainArtifact = valassignment now only runs when parsing succeeds.cmd/importURL.go— same pattern: movedmainArtifact = valinside anelseblock so it only fires on success. Also replaced the rawfmt.Println(err)with a clearer warning message matching the style already used inimport.go.Verification:
Signed-off-by: Adesh Deshmukh adeshkd123@gmail.com