diff --git a/cmd/describe.go b/cmd/describe.go index c2d1d836d8..086c214b3f 100644 --- a/cmd/describe.go +++ b/cmd/describe.go @@ -85,7 +85,7 @@ func runDescribe(cmd *cobra.Command, args []string, newClient ClientFactory) (er return err } if !f.Initialized() { - return errors.New("function not found at this path and no name provided") + return formatError(fn.NewErrNotInitialized(f.Root)) } details, err = client.Describe(cmd.Context(), "", "", f) if err != nil { @@ -97,6 +97,32 @@ func runDescribe(cmd *cobra.Command, args []string, newClient ClientFactory) (er return } +// formatError wraps ErrNotInitialized with user-friendly guidance +func formatError(err error) error { + var errNotInitialized *fn.ErrNotInitialized + if errors.As(err, &errNotInitialized) { + return fmt.Errorf(`%s + +No function found in provided path (current directory or via --path). +You need to be in a function directory (or use --path). + +Try this: + func create --language go myfunction Create a new function + cd myfunction Go into the function directory + func describe Show function description + +Or if you have an existing function: + cd path/to/your/function Go to your function directory + func describe Show function description + +Or use --path to describe from anywhere: + func describe --path /path/to/function + +For more information try 'func describe --help'`, errNotInitialized.Error()) + } + return err +} + // CLI Configuration (parameters) // ------------------------------ diff --git a/cmd/describe_test.go b/cmd/describe_test.go index 9f8a69ff4c..aba1275f7c 100644 --- a/cmd/describe_test.go +++ b/cmd/describe_test.go @@ -24,7 +24,7 @@ func TestDescribe_Default(t *testing.T) { if err == nil { t.Fatal("describing a nonexistent function should error") } - if !strings.Contains(err.Error(), "function not found at this path and no name provided") { + if !strings.Contains(err.Error(), "No function found in provided path") { t.Fatalf("Unexpected error text returned: %v", err) } if describer.DescribeInvoked {