knative / knative/func

cmd: invoke checks f.Validate() before f.Initialized(), producing confusing errors

Open
#3,848 1 comment 0 reactions 1 assignee View on GitHub

@Elvand-Lie is already working on this.

Since Jun 2, 2026.

kind/bug
Dominant language
Go
Stars
365
Forks
223
Avg merge
2d 3h
Merged PRs (30d)
25

Description

Description

In runInvoke() (cmd/invoke.go), the validation checks are in the wrong order compared to every other command:

f, err := fn.NewFunction(cfg.Path)  // Step 1: Load function
if err = f.Validate(); err != nil {  // Step 2: VALIDATE FIRST (wrong)
    fmt.Printf("error validating...")
    return err
}
// ...
if !f.Initialized() {               // Step 3: Check initialized (too late)
    return fmt.Errorf("no function found...")
}

Every other command (run, deploy, delete, describe, subscribe) checks !f.Initialized() immediately after fn.NewFunction(). The invoke command is the only one that calls f.Validate() first.

Impact

When a user runs func invoke in a non-function directory:

  • fn.NewFunction() succeeds (returns an empty Function struct)
  • f.Validate() is called on this empty struct, producing a confusing error like func.yaml contains errors
  • The user-friendly "no function found" message is never reached

Additionally, line 154 uses fmt.Printf to print the error AND returns the same error. Cobra also displays returned errors, causing double error output.

Proposed Fix

  1. Move the !f.Initialized() check before f.Validate()
  2. Remove the fmt.Printf double error output

/kind bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.