func
func copied to clipboard
fix(create): Add helpful error messages for hyphen-prefixed function names mis-parsed as flags
Changes
- :bug: Fix confusing errors when function names start with hyphens
- :gift: Add DNS-1035 naming guidance for mis-parsed arguments
- :sparkles: Detect hyphen-prefixed names across multiple error paths
Adds detection and helpful error messages when function names starting with hyphens (e.g., -test-func, --production-func, -123) are mis-parsed as CLI flags. Users now receive clear guidance about DNS-1035 naming rules instead of confusing "template not found" or "unknown flag" errors.
Implementation:
- Add
wrapFlagParsingError()andwrapFlagParsingErrorWithDetails()helper functions (cmd/errors.go) - Add custom flag error handler in
NewCreateCmd()to intercept Cobra flag parsing errors (cmd/create.go) - Enhance
newInvalidRuntimeError()andnewInvalidTemplateError()to detect mis-parsed names (cmd/create.go)
Error Message Example:
Error: The template 'est-func' was not found for language runtime 'go'.
Available templates for this language runtime are:
cloudevents
http
Note: It looks like '-test-func' was interpreted as the flag '-t' with value 'est-func'.
Function names cannot start with hyphens per DNS-1035 naming rules.
Valid function names must start with a letter (a-z) and can contain letters, numbers, and hyphens.
/kind bug
Fixes #3166
Release Note
Function names starting with hyphens now show helpful DNS-1035 naming guidance instead of confusing flag parsing errors
Hi @RayyanSeliya. Thanks for your PR.
I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test label.
I understand the commands that are listed here.
Instructions 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.
Codecov Report
:x: Patch coverage is 16.66667% with 40 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 59.98%. Comparing base (0bc91f3) to head (ce7c1ed).
:warning: Report is 11 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| cmd/create.go | 26.66% | 19 Missing and 3 partials :warning: |
| cmd/errors.go | 0.00% | 18 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #3167 +/- ##
==========================================
+ Coverage 59.39% 59.98% +0.59%
==========================================
Files 134 134
Lines 13514 13560 +46
==========================================
+ Hits 8026 8134 +108
+ Misses 4547 4453 -94
- Partials 941 973 +32
| Flag | Coverage Δ | |
|---|---|---|
| e2e-tests | 41.49% <0.00%> (+1.31%) |
:arrow_up: |
| integration-tests | 54.56% <16.66%> (+1.53%) |
:arrow_up: |
| unit-tests | 46.61% <16.66%> (-0.13%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
hey @gauron99 can have a look and point me if any tweaks needed !
/ok-to-test
/cc @gauron99
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: lkingland, RayyanSeliya
The full list of commands accepted by this bot can be found here.
The pull request process is described here
- ~~OWNERS~~ [lkingland]
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment