Report a malformed config instead of panicking in pipectl migrate - #7326
Open
omlahore wants to merge 3 commits into
Open
Report a malformed config instead of panicking in pipectl migrate#7326omlahore wants to merge 3 commits into
omlahore wants to merge 3 commits into
Conversation
migrateApplicationConfig unmarshals a user's YAML into map[string]any and then asserts on three lookups without the comma-ok: spec, spec.pipeline.stages and kind. Any of them holding another type, or being absent, panics the CLI with an interface conversion instead of telling the user which field is wrong. Six configs a user could plausibly write all panic today, including a file with no kind at all. The same function already uses the checked form two lines further down for stages[] and stages[].with, so this is an omission rather than a convention. Return an error naming the field and the type found. Signed-off-by: Om <omlahore47@gmail.com>
omlahore
requested review from
armistcxy,
mohammedfirdouss and
t-kikuc
and
a lite review from Copilot
September 6, 2026 20:03
✅ Deploy Preview for pipecd-site canceled.
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The newly added Go test file is missing the repository-standard Apache 2.0 license header at the top.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves the robustness of pipectl migrate application-config by replacing unsafe type assertions on user-supplied YAML with checked assertions that return descriptive errors, preventing CLI panics on malformed configs.
Changes:
- Add validation for
spec,spec.pipeline,spec.pipeline.stages, andkindwhen decoding YAML intomap[string]any. - Return structured errors (and log them) instead of panicking on unexpected shapes/types.
- Add regression tests ensuring malformed configs don’t panic and instead return errors.
File summaries
| File | Description |
|---|---|
| pkg/app/pipectl/cmd/migrate/application_config.go | Replaces panic-prone type assertions with comma-ok checks and explicit errors for invalid config shapes. |
| pkg/app/pipectl/cmd/migrate/malformed_config_test.go | Adds tests covering several malformed YAML shapes to ensure errors are returned (not panics). |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The default branch re-asserted cfg["kind"].(string) after the switch had already been entered on a checked value, so the same lookup was asserted twice. Use the string that was already validated. Signed-off-by: Om <omlahore47@gmail.com>
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.
What happens
pipectl migrate application-configreads a user's YAML intomap[string]anyand then asserts on three lookups out of it without the comma-ok, so a file with the wrong shape panics the CLI instead of being reported.application_config.go, on3321879:cfgcomes straight fromos.ReadFilethenyaml.Unmarshal(data, &cfg)a few lines above, so every one of those lookups can hold something other than the expected type, or nothing at all.Reproduction
Six configs a user could plausibly write, each in a file passed to
migrateApplicationConfig. All six panic before this change:A config file with no
kind:is enough.The change
Each of the three uses the checked form and returns an error naming the field and the type that was actually there, matching how the same function already handles
stages[]andstages[].withtwo lines further down:So this is an omission rather than a different convention.
spec.pipeline.stagesbeing absent stays valid and is not an error, only a non-list value is.All six cases pass after the change, and
go test ./pkg/app/pipectl/...is green.