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
- Move the
!f.Initialized() check before f.Validate()
- Remove the
fmt.Printf double error output
/kind bug
Description
In
runInvoke()(cmd/invoke.go), the validation checks are in the wrong order compared to every other command:Every other command (
run,deploy,delete,describe,subscribe) checks!f.Initialized()immediately afterfn.NewFunction(). Theinvokecommand is the only one that callsf.Validate()first.Impact
When a user runs
func invokein 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 errorsAdditionally, line 154 uses
fmt.Printfto print the error AND returns the same error. Cobra also displays returned errors, causing double error output.Proposed Fix
!f.Initialized()check beforef.Validate()fmt.Printfdouble error output/kind bug