Skip to content

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

@Elvand-Lie

Description

@Elvand-Lie

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

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions