Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOT-1421] Improve command feedbacks for users #52

Open
polldo opened this issue Oct 15, 2021 · 0 comments
Open

[IOT-1421] Improve command feedbacks for users #52

polldo opened this issue Oct 15, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@polldo
Copy link
Contributor

polldo commented Oct 15, 2021

We could return specific types of errors (instead of generic ones) and then depending on it understand what kind of feedback we should give to the user.

Eg:

diff --git a/cli/dashboard/create.go b/cli/dashboard/create.go
index 211dca7..bfcc0d9 100644
--- a/cli/dashboard/create.go
+++ b/cli/dashboard/create.go
@@ -64,13 +64,21 @@ func runCreateCommand(cmd *cobra.Command, args []string) {
 		params.Name = &createFlags.name
 	}
 
-	dashboard, err := dashboard.Create(params)
+	dboard, err := dashboard.Create(params)
 	if err != nil {
-		feedback.Errorf("Error during dashboard create: %v", err)
+		switch err.(type) {
+		case dashboard.ErrMissingName:
+			feedback.Errorf(`Error during dashboard create: %v.
+
+It seems like the provided template doesn't have a default name for the
+dashboard,  please provide one with the --name option."`, err)
+		default:
+			feedback.Errorf("Error during dashboard create: %v", err)
+		}
 		os.Exit(errorcodes.ErrGeneric)
 	}
 
-	feedback.PrintResult(createResult{dashboard})
+	feedback.PrintResult(createResult{dboard})
 }
 
 type createResult struct {
diff --git a/command/dashboard/create.go b/command/dashboard/create.go
index d92c594..ae77261 100644
--- a/command/dashboard/create.go
+++ b/command/dashboard/create.go
@@ -18,13 +18,17 @@
 package dashboard
 
 import (
-	"errors"
-
 	"github.com/arduino/arduino-cloud-cli/internal/config"
 	"github.com/arduino/arduino-cloud-cli/internal/iot"
 	"github.com/arduino/arduino-cloud-cli/internal/template"
 )
 
+type ErrMissingName struct{}
+
+func (ErrMissingName) Error() string {
+	return "dashboard name not specified"
+}
+
 // CreateParams contains the parameters needed to create a new dashboard.
 type CreateParams struct {
 	Name     *string           // Name of the new dashboard
@@ -54,7 +58,7 @@ func Create(params *CreateParams) (*DashboardInfo, error) {
 	}
 	// If name is not specified in the template, it should be passed as parameter
 	if dashboard.Name == "" {
-		return nil, errors.New("dashboard name not specified")
+		return nil, ErrMissingName{}
 	}
 
 	newDashboard, err := iotClient.DashboardCreate(dashboard)

Originally posted by @glumia in #50 (comment)

@polldo polldo changed the title Improve command feedbacks for users [IOT-1421] Improve command feedbacks for users Oct 15, 2021
@per1234 per1234 added the enhancement New feature or request label Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants