fix: preserve mainArtifact default on parse failure in import and import-url#460
fix: preserve mainArtifact default on parse failure in import and import-url#460AdeshDeshmukh wants to merge 3 commits 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.
| 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 | ||
| } |
| 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 | ||
| } | ||
| } |
Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
|
@AdeshDeshmukh Please look at Copilot comments The bug being addressed is real, but I don’t think I’d like this adjusted so we only trim the suffix when the tail actually parses as Also, for |
…corruption cmd/import.go: only truncate path when suffix is a valid boolean cmd/importURL.go: extract parseImportURLArg() with right-to-left scan to handle URLs with ports/paths while fixing bool parse cmd/importURL_test.go: 14 test cases covering URL+port, bool, secret, and malformed bool scenarios Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
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