cmd: invoke checks f.Validate() before f.Initialized(), producing confusing errors
Open
@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 likefunc.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
- Move the
!f.Initialized()check beforef.Validate() - Remove the
fmt.Printfdouble error output
/kind bug
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.