-
Notifications
You must be signed in to change notification settings - Fork 8
/
errs.go
114 lines (86 loc) · 4.49 KB
/
errs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package errs
import (
"encoding/json"
"errors"
"fmt"
"github.com/urfave/cli"
)
// ErrMustLogin represents an error when a user must login to continue
var ErrMustLogin = cli.NewExitError("You must login to perform that command.", -1)
// ErrAlreadyLoggedIn represents an error where a user is attempting to login,
// but has an existing session.
var ErrAlreadyLoggedIn = cli.NewExitError("You're already logged in!", -1)
// ErrAlreadyLoggedOut represents an error where a user is attempting to logut,
// but does not have an existing session.
var ErrAlreadyLoggedOut = cli.NewExitError("You're already logged out!", -1)
// ErrNotLoggedIn represents an error where a user must log in to continue
var ErrNotLoggedIn = cli.NewExitError("You are not logged in!", -1)
// ErrInvalidResourceName represents an error where a user has provided an
// invalid resource name
var ErrInvalidResourceName = cli.NewExitError("You've provided an invalid resource name!", -1)
// ErrProductNotFound represents an error where the provided user's product
// label does not exist.
var ErrProductNotFound = cli.NewExitError("The provided product does not exist!", -1)
// ErrPlanNotFound represents an error where the provided user's plan label
// does not exist.
var ErrPlanNotFound = cli.NewExitError("The provided plan does not exist!", -1)
// ErrResourceNotFound represents an error where the provided user's resource label
// does not exist
var ErrResourceNotFound = cli.NewExitError("The provided resource does not exist!", -1)
// ErrTeamNotFound represents an error where the provided user's team label does not exist
var ErrTeamNotFound = cli.NewExitError("The provided team does not exist!", -1)
// ErrProjectNotFound represents an error where the provided project does not exist
var ErrProjectNotFound = cli.NewExitError("The provided project does not exist!", -1)
// ErrRegionNotFound represents an error where the provided user's region label
// does not exist
var ErrRegionNotFound = cli.NewExitError("The provided region does not exist!", -1)
// ErrNoApps represents an error where the action requires a resource app but none exist
var ErrNoApps = cli.NewExitError("There are no resources with apps", -1)
// ErrNoTeams represents an error where at least one team is required for an action, but none are
// available
var ErrNoTeams = cli.NewExitError("No teams found", -1)
// ErrNoProjects represents an error when there are no projects found
var ErrNoProjects = cli.NewExitError("No projects found", -1)
// ErrNoResources represents an error where no resources exist to preform some action on
var ErrNoResources = cli.NewExitError("No resources found", -1)
// ErrNoPlans represents an error where no plans exist for the resource being created or updated
var ErrNoPlans = cli.NewExitError("No plans found for this product", -1)
// ErrNoProviders represents an error where no providers exist
var ErrNoProviders = cli.NewExitError("No providers found", -1)
// ErrNoProducts represents an error where no products exist
var ErrNoProducts = cli.NewExitError("No products found", -1)
// ErrTooManyArgs represents an error where a user has provided too many
// command line arguments
var ErrTooManyArgs = cli.NewExitError("You've provided too many command line arguments!", -1)
// ErrTooFewArgs represents an error where a user has provided too few
// command line arguments
var ErrTooFewArgs = cli.NewExitError("You've provided too few command line arguments!", -1)
// ErrSomethingWentHorriblyWrong represents an error that is completely out of
// our control and unexpected (such as a 500 from the API)
var ErrSomethingWentHorriblyWrong = cli.NewExitError("Something went horribly wrong; please try again!", -1)
// NewUsageExitError returns a new error that includes the usage string for the
// givne command along with the message from the given error.
func NewUsageExitError(ctx *cli.Context, err error) error {
fmt.Printf("Invalid usage: %s\n\n", err.Error())
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, -1)
return nil
}
// NewErrorExitError creates an ExitError with an appended error message
func NewErrorExitError(message string, err error) error {
return cli.NewExitError(message+"\n"+err.Error(), -1)
}
type stripeError struct {
Message string `json:"message"`
}
func (s stripeError) Error() error {
return errors.New(s.Message)
}
// NewStripeError marshals the stripe json error to a human error
func NewStripeError(err error) error {
var sErr stripeError
jErr := json.Unmarshal([]byte(err.Error()), &sErr)
if jErr != nil {
return err
}
return sErr.Error()
}