Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
// ------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cmd/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading