You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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:
Originally posted by @glumia in #50 (comment)
The text was updated successfully, but these errors were encountered: