fix(cmd): return error when config add flags are partially provided#3762
fix(cmd): return error when config add flags are partially provided#3762Ankitsinghsisodya wants to merge 2 commits into
Conversation
Added validation to ensure that the --name flag cannot be provided without the --value flag, and vice versa, in both environment and label commands. This prevents the creation of invalid configurations. Added corresponding unit tests to verify the expected error behavior when these flags are misused.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ankitsinghsisodya The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Ankitsinghsisodya. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds CLI validation to prevent creating labels/envs with missing name/value pairs, and introduces regression tests to ensure invalid flag combinations fail fast.
Changes:
- Add input validation for
config labels addwhen only one of--name/--valueis provided. - Add input validation for
config envs addwhen--nameis provided without--value. - Add tests covering the new validation behavior for labels and envs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cmd/config_test.go | Adds regression tests for invalid --name/--value combinations and a helper for labels command setup. |
| cmd/config_labels.go | Rejects labels add invocations where only one of --name/--value is specified. |
| cmd/config_envs.go | Rejects envs add when --name is provided without --value. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #3762 +/- ##
==========================================
- Coverage 57.06% 51.43% -5.64%
==========================================
Files 181 181
Lines 21145 21154 +9
==========================================
- Hits 12067 10881 -1186
- Misses 7855 9234 +1379
+ Partials 1223 1039 -184
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Updated error handling in the label command to use errors.New instead of fmt.Errorf for consistency in flag validation messages. This change improves clarity and maintains uniformity in error reporting when required flags are missing.
Problem
config envs add --name=KEY(without--value) silently writesfn.Env{Name: &"KEY", Value: nil}tofunc.yaml. This entry is invisiblein
config envs list, renders asKEY=(empty string) at deploy time, andfails
ValidateEnvsat build time with "env entry #N is missing valuefield". The OR condition in the non-interactive guard allowed the partial
set to bypass the interactive prompt and go straight to Save.
config labels add --name=Foo(without--value) silently drops the flagand launches the interactive prompt with no explanation, because the AND
condition means the non-interactive block is never entered.
Changes
cmd/config_envs.go--nameis provided but--valueis not, return--value is required when --name is providedbefore calling Save.--value='{{ secret:S }}'without--name) isunaffected — the guard only triggers when name is set and value is nil.
cmd/config_labels.go--nameor only--valueis provided, return a clear error rather than silently enteringinteractive mode.
Tests
Added to
cmd/config_test.go:TestEnvsAddNameWithoutValue— verifies error is returned and Save isnot called.
TestLabelsAddNameWithoutValue— verifies error when--nameis givenwithout
--value.TestLabelsAddValueWithoutName— verifies error when--valueis givenwithout
--name.