Skip to content

fix(cmd): remove unreachable dead code in --extension validation#3839

Open
Ankitsinghsisodya wants to merge 1 commit into
knative:mainfrom
Ankitsinghsisodya:fix/invoke-dead-code-extension-validation
Open

fix(cmd): remove unreachable dead code in --extension validation#3839
Ankitsinghsisodya wants to merge 1 commit into
knative:mainfrom
Ankitsinghsisodya:fix/invoke-dead-code-extension-validation

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

Problem

In cmd/invoke.go, the --extension validation block contains two consecutive
if checks, but the second is permanently unreachable:

if effectiveFormat != "cloudevent" {          // returns here if true
    return fmt.Errorf("--extension (-e) is only valid with cloudevents")
}
if effectiveFormat != "" && effectiveFormat != "cloudevent" { // DEAD — never reached
    return fmt.Errorf("--extension flag is only valid with cloudevent format")
}

If the first condition is true the function has already returned. By the time
execution reaches the second if, effectiveFormat is guaranteed to equal
"cloudevent", so the second condition is always false. The duplicate error
message is also inconsistently worded.

Fix

Remove the unreachable block. The single check at line 175 is sufficient and
already carries the correct error message.

Testing

go test ./cmd/...

…devent format

The check for the extension flag being valid only with the cloudevent format has been simplified by removing the redundant validation. This streamlines the code and clarifies the intended usage of the extension flag.
Copilot AI review requested due to automatic review settings May 24, 2026 11:55
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 24, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Details 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 dsimansk and jrangelramos May 24, 2026 11:55
@knative-prow knative-prow Bot added the size/XS 🤖 PR changes 0-9 lines, ignoring generated files. label May 24, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 24, 2026

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 /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.

Details

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.

@knative-prow knative-prow Bot added the needs-ok-to-test 🤖 Needs an org member to approve testing label May 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Removes redundant validation logic around the --extension flag when the invoke output format is not CloudEvents.

Changes:

  • Deleted a duplicate conditional check that produced a second, slightly different error message for the same invalid state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/invoke.go
@@ -175,9 +175,6 @@ func runInvoke(cmd *cobra.Command, _ []string, newClient ClientFactory) (err err
if effectiveFormat != "cloudevent" {
return fmt.Errorf("--extension (-e) is only valid with cloudevents")
@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.46%. Comparing base (692383b) to head (8ff1f28).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3839      +/-   ##
==========================================
+ Coverage   53.44%   53.46%   +0.01%     
==========================================
  Files         200      200              
  Lines       23450    23447       -3     
==========================================
+ Hits        12534    12535       +1     
+ Misses       9662     9658       -4     
  Partials     1254     1254              
Flag Coverage Δ
e2e 33.72% <ø> (+<0.01%) ⬆️
e2e go 29.66% <ø> (+<0.01%) ⬆️
e2e node 25.96% <ø> (+<0.01%) ⬆️
e2e python 30.00% <ø> (+<0.01%) ⬆️
e2e quarkus 26.07% <ø> (+<0.01%) ⬆️
e2e rust 25.54% <ø> (+<0.01%) ⬆️
e2e springboot 24.21% <ø> (+<0.01%) ⬆️
e2e typescript 26.06% <ø> (+<0.01%) ⬆️
e2e-config-ci 26.78% <ø> (+<0.01%) ⬆️
integration 15.77% <ø> (-0.01%) ⬇️
unit macos-14 42.23% <ø> (+<0.01%) ⬆️
unit macos-latest 42.23% <ø> (+<0.01%) ⬆️
unit ubuntu-24.04-arm 42.53% <ø> (+<0.01%) ⬆️
unit ubuntu-latest 43.09% <ø> (+<0.01%) ⬆️
unit windows-latest 42.30% <ø> (+<0.01%) ⬆️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/XS 🤖 PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants