From 526c031a4ba57ba3ef32dbb761988ec27af3225a Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Sat, 6 Sep 2025 20:25:04 +0530 Subject: [PATCH 1/4] improve error message for func describe and guide users correctly Signed-off-by: RayyanSeliya --- cmd/describe.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/describe.go b/cmd/describe.go index c2d1d836d8..f588135ed0 100644 --- a/cmd/describe.go +++ b/cmd/describe.go @@ -3,7 +3,6 @@ package cmd import ( "encoding/json" "encoding/xml" - "errors" "fmt" "io" "os" @@ -85,7 +84,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 fmt.Errorf("no function found in current directory.\nYou need to be inside a function directory to get the function description.\n\nTry this:\n func create --language go myfunction Create a new function\n cd myfunction Go into the function directory\n func describe Show function description\n\nOr if you have an existing function:\n cd path/to/your/function Go to your function directory\n func describe Show function description") } details, err = client.Describe(cmd.Context(), "", "", f) if err != nil { From a4cc4cf3483567a12a62d347617f8c1ea3aafffa Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Tue, 16 Sep 2025 16:12:52 +0530 Subject: [PATCH 2/4] Improve the description formatting using backticks Signed-off-by: RayyanSeliya --- cmd/describe.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/describe.go b/cmd/describe.go index f588135ed0..002533aa28 100644 --- a/cmd/describe.go +++ b/cmd/describe.go @@ -84,7 +84,17 @@ func runDescribe(cmd *cobra.Command, args []string, newClient ClientFactory) (er return err } if !f.Initialized() { - return fmt.Errorf("no function found in current directory.\nYou need to be inside a function directory to get the function description.\n\nTry this:\n func create --language go myfunction Create a new function\n cd myfunction Go into the function directory\n func describe Show function description\n\nOr if you have an existing function:\n cd path/to/your/function Go to your function directory\n func describe Show function description") + return fmt.Errorf(`no function found in current directory. +You need to be inside a function directory to get the function description. + +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`) } details, err = client.Describe(cmd.Context(), "", "", f) if err != nil { From 6f7a6e62ffeb3c1dd2ed9846f76d82029712029e Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Wed, 24 Sep 2025 16:19:53 +0530 Subject: [PATCH 3/4] Fix the failing test updated describe_test.go to include new description Signed-off-by: RayyanSeliya --- cmd/describe_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/describe_test.go b/cmd/describe_test.go index 9f8a69ff4c..112c8c4524 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 current directory") { t.Fatalf("Unexpected error text returned: %v", err) } if describer.DescribeInvoked { From 3901142bfab081c6382ae399202f31c7fd6c70d5 Mon Sep 17 00:00:00 2001 From: RayyanSeliya Date: Fri, 17 Oct 2025 16:17:52 +0530 Subject: [PATCH 4/4] use 2 layer approach to have concistency in the code Signed-off-by: RayyanSeliya --- cmd/describe.go | 39 ++++++++++++++++++++++++++++----------- cmd/describe_test.go | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/cmd/describe.go b/cmd/describe.go index 002533aa28..086c214b3f 100644 --- a/cmd/describe.go +++ b/cmd/describe.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "encoding/xml" + "errors" "fmt" "io" "os" @@ -84,17 +85,7 @@ func runDescribe(cmd *cobra.Command, args []string, newClient ClientFactory) (er return err } if !f.Initialized() { - return fmt.Errorf(`no function found in current directory. -You need to be inside a function directory to get the function description. - -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`) + return formatError(fn.NewErrNotInitialized(f.Root)) } details, err = client.Describe(cmd.Context(), "", "", f) if err != nil { @@ -106,6 +97,32 @@ Or if you have an existing function: 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 112c8c4524..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(), "no function found in current directory") { + if !strings.Contains(err.Error(), "No function found in provided path") { t.Fatalf("Unexpected error text returned: %v", err) } if describer.DescribeInvoked {