Skip to content

Commit

Permalink
Merge pull request #148 from planetscale/fatih/better-not-found-errors
Browse files Browse the repository at this point in the history
cmd: improve "Error: Not Found" messages
  • Loading branch information
fatih authored Apr 6, 2021
2 parents 148b58f + f724f47 commit 708ed76
Show file tree
Hide file tree
Showing 31 changed files with 53 additions and 34 deletions.
7 changes: 6 additions & 1 deletion internal/cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ func writeDefaultOrganization(ctx context.Context, accessToken, authURL string)

orgs, err := client.Organizations.List(ctx)
if err != nil {
return err
switch cmdutil.ErrCode(err) {
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
return errors.Wrap(err, "error listing organizations")
}
}

if len(orgs) > 0 {
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/backup/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ func CreateCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s", cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database))
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:

return cmdutil.MalformedError(err)
default:
return err
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/backup/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func DeleteCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in branch %s of %s\n", cmdutil.BoldBlue(backup), cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database))
return fmt.Errorf("backup %s does not exist in branch %s of %s (organization: %s)\n",
cmdutil.BoldBlue(backup), cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/backup/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func GetCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in branch %s of %s\n", cmdutil.BoldBlue(backup), cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database))
return fmt.Errorf("backup %s does not exist in branch %s of %s (organization: %s)\n",
cmdutil.BoldBlue(backup), cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/backup/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func ListCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n", cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database))
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)\n",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/branch/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func CreateCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n", cmdutil.BoldBlue(source), cmdutil.BoldBlue(cfg.Organization))
return fmt.Errorf("source database %s does not exist in organization %s\n",
cmdutil.BoldBlue(source), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/branch/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func DeleteCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n", cmdutil.BoldBlue(source), cmdutil.BoldBlue(cfg.Organization))
return fmt.Errorf("source database %s does not exist in organization %s\n",
cmdutil.BoldBlue(source), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/branch/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func GetCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s", cmdutil.BoldBlue(branch), cmdutil.BoldBlue(source))
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(source), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/branch/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func ListCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n", cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
return fmt.Errorf("database %s does not exist in organization %s\n",
cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/branch/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func StatusCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s", cmdutil.BoldBlue(branch), cmdutil.BoldBlue(source))
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(source), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/database/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func CreateCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in\n", cmdutil.BoldBlue(cfg.Organization))
return fmt.Errorf("organization %s does not exist\n", cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/database/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func DeleteCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n", cmdutil.BoldBlue(name), cmdutil.BoldBlue(cfg.Organization))
return fmt.Errorf("database %s does not exist in organization %s\n",
cmdutil.BoldBlue(name), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/database/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func GetCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n", cmdutil.BoldBlue(name), cmdutil.BoldBlue(cfg.Organization))
return fmt.Errorf("database %s does not exist in organization %s\n",
cmdutil.BoldBlue(name), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/database/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ListCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist\n", cmdutil.BoldBlue(cfg.Organization))
return fmt.Errorf("organization %s does not exist\n", cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func CloseCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s/%s does not exist in %s\n",
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s\n",
cmdutil.BoldBlue(database), cmdutil.BoldBlue(number), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func CreateCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n",
return fmt.Errorf("database %s does not exist in %s\n",
cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func DeployCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s/%s does not exist in %s\n",
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s\n",
cmdutil.BoldBlue(database), cmdutil.BoldBlue(number), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func DiffCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s/%s does not exist in %s\n",
return fmt.Errorf("deploy rquest '%s/%s' does not exist in organization %s\n",
cmdutil.BoldBlue(database), cmdutil.BoldBlue(number), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ListCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n",
return fmt.Errorf("database %s does not exist in organization %s\n",
cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ReviewCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s/%s does not exist in %s\n",
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s\n",
cmdutil.BoldBlue(database), cmdutil.BoldBlue(number), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deployrequest/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ShowCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s/%s does not exist in %s\n",
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s\n",
cmdutil.BoldBlue(database), cmdutil.BoldBlue(number), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/org/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func SwitchCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist\n", cmdutil.BoldBlue(orgName))
return fmt.Errorf("organization %s does not exist\n", cmdutil.BoldBlue(orgName))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ second argument:
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database))
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/snapshot/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func CreateCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database))
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/snapshot/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("snapshot id %q does not exist", cmdutil.BoldBlue(id))
return fmt.Errorf("snapshot id %s does not exist (organization: %s)", cmdutil.BoldBlue(id), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/snapshot/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func ListCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database))
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
cmdutil.BoldBlue(branch), cmdutil.BoldBlue(database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/snapshot/request_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func RequestDeployCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("snapshot id %q does not exist", cmdutil.BoldBlue(id))
return fmt.Errorf("snapshot id %s does not exist (organization: %s)",
cmdutil.BoldBlue(id), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/token/add-access.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ For a complete list of the access permissions that can be granted to a token, se
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n",
return fmt.Errorf("database %s does not exist in organization %s\n",
cmdutil.BoldBlue(cfg.Database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/token/delete-access.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func DeleteAccessCmd(cfg *config.Config) *cobra.Command {
if err := client.ServiceTokens.DeleteAccess(ctx, req); err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n",
return fmt.Errorf("database %s or token does not exist in organization %s\n",
cmdutil.BoldBlue(cfg.Database), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/token/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func DeleteCmd(cfg *config.Config) *cobra.Command {
if err := client.ServiceTokens.Delete(ctx, req); err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("token does not exist in %s\n", cmdutil.BoldBlue(cfg.Organization))
return fmt.Errorf("token does not exist in organization %s\n",
cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/token/get-access.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func GetCmd(cfg *config.Config) *cobra.Command {
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("%s does not exist in %s\n",
return fmt.Errorf("access %s does not exist in organization %s\n",
cmdutil.BoldBlue(name), cmdutil.BoldBlue(cfg.Organization))
case planetscale.ErrResponseMalformed:
return cmdutil.MalformedError(err)
Expand Down

0 comments on commit 708ed76

Please sign in to comment.