fix: return error for malformed --extension flag values#3852
fix: return error for malformed --extension flag values#3852Ankitsinghsisodya wants to merge 2 commits into
Conversation
|
[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 Regular contributors should join the org to skip this step. 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. |
- Added `extensionsMap` method to `invokeConfig` to parse key=value extensions and return a map. - Introduced error handling for malformed extension entries. - Created unit tests `TestInvokeExtensionsMapValid` and `TestInvokeExtensionsMapMalformed` to validate the parsing logic and error conditions. This enhances the robustness of the extension handling in the invoke command.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds strict parsing/validation for --extension CLI entries so malformed values error out instead of being silently ignored, and introduces tests for the new behavior.
Changes:
- Parse
Extensionsaskey=valuewithstrings.SplitN(..., 2)and return an error when malformed. - Wire parsing errors into
runInvokeso invoke fails fast on invalid extensions. - Add unit tests covering valid values (including values containing
=) and malformed entries.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/invoke.go | Changes extensions parsing to return (map, error) and propagates parsing errors into invoke execution. |
| cmd/invoke_test.go | Adds tests to validate correct parsing behavior and erroring on malformed extensions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| func (c invokeConfig) extensionsMap() map[string]string { | ||
| extensionsMap := make(map[string]string) | ||
| func (c invokeConfig) extensionsMap() (map[string]string, error) { |
788bb83 to
3fbb349
Compare
- Renamed `extensionsMap` method to `parseExtensions` for clarity. - Enhanced validation to check for empty keys in extension entries. - Updated unit tests to cover cases for missing '=' and empty keys in extensions. This change improves the robustness and clarity of extension parsing in the invoke command.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3852 +/- ##
==========================================
+ Coverage 53.44% 53.47% +0.02%
==========================================
Files 200 200
Lines 23450 23455 +5
==========================================
+ Hits 12533 12542 +9
+ Misses 9662 9659 -3
+ Partials 1255 1254 -1
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:
|
Problem
extensionsMap()incmd/invoke.gosilently dropped any--extensionvalue that did not contain=. The invocation proceeded with fewer extensions than the user specified, with no feedback — particularly confusing when debugging CloudEvent routing.Changes
cmd/invoke.goextensionsMap()signature frommap[string]stringto(map[string]string, error).=(e.g.invalid --extension "badformat": must be in key=value format).extensionsMap→resultfor clarity.InvokeMessage.cmd/invoke_test.goTestInvokeExtensionsMapValid: verifies correct parsing including values that themselves contain=(e.g. base64 strings likefoo=bar=baz).TestInvokeExtensionsMapMalformed: verifies that a missing=produces an error rather than a silent drop.Testing