Skip to content

fix: preserve mainArtifact default on parse failure in import and import-url#460

Open
AdeshDeshmukh wants to merge 1 commit into
microcks:masterfrom
AdeshDeshmukh:fix/mainartifact-parse-fallback
Open

fix: preserve mainArtifact default on parse failure in import and import-url#460
AdeshDeshmukh wants to merge 1 commit into
microcks:masterfrom
AdeshDeshmukh:fix/mainartifact-parse-fallback

Conversation

@AdeshDeshmukh

Copy link
Copy Markdown

Both the import and import-url commands accept a :true or :false suffix to mark an artifact as primary or secondary. If that suffix is malformed (e.g. :tru or :xyz), strconv.ParseBool returns false as its zero value — and that false was being unconditionally assigned to mainArtifact, silently overriding the intended default of true.

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 mainArtifact when ParseBool succeeds. On failure, print a clear warning and keep the default value of true.

Files changed:

  • cmd/import.go — replaced the outer var err error + direct assignment with a scoped val variable inside an if/else block. The mainArtifact = val assignment now only runs when parsing succeeds.
  • cmd/importURL.go — same pattern: moved mainArtifact = val inside an else block so it only fires on success. Also replaced the raw fmt.Println(err) with a clearer warning message matching the style already used in import.go.

Verification:

go build ./...  — passes
go vet ./...   — no new issues
go test ./...  — all tests pass (1 pre-existing failure in TestDeleteContext, unrelated)

Signed-off-by: Adesh Deshmukh adeshkd123@gmail.com

…ort-url

Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
@AdeshDeshmukh AdeshDeshmukh requested a review from lbroudoux as a code owner June 17, 2026 02:47
Copilot AI review requested due to automatic review settings June 17, 2026 02:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mainArtifact from being overwritten when strconv.ParseBool returns an error.
  • Replace raw error printing with a clearer parse-failure message.
  • Refactor parsing in cmd/import.go to use a scoped parseErr variable 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 thread cmd/importURL.go
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 thread cmd/import.go
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants