Skip to content

Conversation

@RayyanSeliya
Copy link
Contributor

Changes

  • πŸ› Fix confusing errors when function names start with hyphens
  • 🎁 Add DNS-1035 naming guidance for mis-parsed arguments
  • ✨ 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() and wrapFlagParsingErrorWithDetails() helper functions (cmd/errors.go)
  • Add custom flag error handler in NewCreateCmd() to intercept Cobra flag parsing errors (cmd/create.go)
  • Enhance newInvalidRuntimeError() and newInvalidTemplateError() 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

@knative-prow knative-prow bot added the kind/bug Categorizes issue or PR as related to a bug. label Nov 2, 2025
@knative-prow
Copy link

knative-prow bot commented Nov 2, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: RayyanSeliya
Once this PR has been reviewed and has the lgtm label, please assign linkvt for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot requested review from jrangelramos and nainaz November 2, 2025 18:53
@knative-prow knative-prow bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 2, 2025
@knative-prow
Copy link

knative-prow bot commented Nov 2, 2025

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
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

❌ Patch coverage is 16.66667% with 40 lines in your changes missing coverage. Please review.
βœ… Project coverage is 59.98%. Comparing base (0bc91f3) to head (ce7c1ed).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
cmd/create.go 26.66% 19 Missing and 3 partials ⚠️
cmd/errors.go 0.00% 18 Missing ⚠️
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%) ⬆️
integration-tests 54.56% <16.66%> (+1.53%) ⬆️
unit-tests 46.61% <16.66%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RayyanSeliya
Copy link
Contributor Author

hey @gauron99 can have a look and point me if any tweaks needed !

Signed-off-by: RayyanSeliya <[email protected]>
@RayyanSeliya
Copy link
Contributor Author

/ok-to-test

@knative-prow knative-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

func create: Hyphen-prefixed names mis-parsed as flags

1 participant