Skip to content

Commit 3d1ee5e

Browse files
authored
feat: warn when func invoke type mismatches declared function type (knative#3162)
* adding check * fix * minor mistake
1 parent 31ccae9 commit 3d1ee5e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cmd/invoke.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ func runInvoke(cmd *cobra.Command, _ []string, newClient ClientFactory) (err err
153153
fmt.Printf("error validating function at '%v'. %v\n", f.Root, err)
154154
return err
155155
}
156+
157+
if cfg.Format != "" && f.Invoke != "" && cfg.Format != f.Invoke {
158+
fmt.Fprintf(cmd.OutOrStdout(),
159+
"Warning: invoking as %q, but function declares type %q in func.yaml.\n"+
160+
" This may fail unless you rebuild or update func.yaml with `invoke: %s`.\n\n",
161+
cfg.Format, f.Invoke, cfg.Format)
162+
}
163+
156164
if !f.Initialized() {
157165
return fmt.Errorf("no function found in current directory.\nYou need to be inside a function directory to invoke it.\n\nTry this:\n func create --language go myfunction Create a new function\n cd myfunction Go into the function directory\n func invoke Now you can invoke it\n\nOr if you have an existing function:\n cd path/to/your/function Go to your function directory\n func invoke Invoke the function")
158166
}

0 commit comments

Comments
 (0)