Skip to content

Commit

Permalink
chore: add stacktrace to all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Dec 16, 2023
1 parent 21110eb commit a5308b4
Show file tree
Hide file tree
Showing 58 changed files with 399 additions and 321 deletions.
12 changes: 6 additions & 6 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package cmd

import (
"bytes"
"errors"
"fmt"
"io"
"os"
"os/user"
"strings"
"time"

"github.com/go-errors/errors"
"github.com/google/uuid"
"github.com/mattn/go-isatty"
"github.com/spf13/afero"
Expand All @@ -20,18 +20,18 @@ import (
)

var (
ErrMissingToken = errors.New("Cannot use automatic login flow inside non-TTY environments. Please provide " + utils.Aqua("--token") + " flag or set the " + utils.Aqua("SUPABASE_ACCESS_TOKEN") + " environment variable.")
ErrMissingToken = errors.Errorf("Cannot use automatic login flow inside non-TTY environments. Please provide %s flag or set the %s environment variable.", utils.Aqua("--token"), utils.Aqua("SUPABASE_ACCESS_TOKEN"))
)

func generateTokenName() (string, error) {
user, err := user.Current()
if err != nil {
return "", fmt.Errorf("cannot retrieve username: %w", err)
return "", errors.Errorf("cannot retrieve username: %w", err)
}

hostname, err := os.Hostname()
if err != nil {
return "", fmt.Errorf("cannot retrieve hostname: %w", err)
return "", errors.Errorf("cannot retrieve hostname: %w", err)
}

return fmt.Sprintf("cli_%s@%s_%d", user.Username, hostname, time.Now().Unix()), nil
Expand All @@ -58,7 +58,7 @@ var (
} else if cmd.Flags().Changed("token") {
token, err := cmd.Flags().GetString("token")
if err != nil {
return fmt.Errorf("cannot parse 'token' flag: %w", err)
return errors.Errorf("cannot parse 'token' flag: %w", err)
}
params.Token = token
} else if token := os.Getenv("SUPABASE_ACCESS_TOKEN"); token != "" {
Expand All @@ -83,7 +83,7 @@ var (
if cmd.Flags().Changed("name") {
name, err := cmd.Flags().GetString("name")
if err != nil {
return fmt.Errorf("cannot parse 'name' flag: %w", err)
return errors.Errorf("cannot parse 'name' flag: %w", err)
}
params.TokenName = name
} else {
Expand Down
5 changes: 2 additions & 3 deletions cmd/sslEnforcement.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package cmd

import (
"fmt"

"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/supabase/cli/internal/ssl_enforcement/get"
Expand All @@ -25,7 +24,7 @@ var (
Short: "Update SSL enforcement configuration",
RunE: func(cmd *cobra.Command, args []string) error {
if !dbEnforceSsl && !dbDisableSsl {
return fmt.Errorf("enable/disable not specified")
return errors.New("enable/disable not specified")
}
return update.Run(cmd.Context(), flags.ProjectRef, dbEnforceSsl, afero.NewOsFs())
},
Expand Down
9 changes: 4 additions & 5 deletions cmd/sso.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package cmd

import (
"fmt"

"github.com/go-errors/errors"
"github.com/spf13/cobra"

"github.com/supabase/cli/internal/sso/create"
Expand Down Expand Up @@ -66,7 +65,7 @@ var (
Example: ` supabase sso remove b5ae62f9-ef1d-4f11-a02b-731c8bbb11e8 --project-ref mwjylndxudmiehsxhmmz`,
RunE: func(cmd *cobra.Command, args []string) error {
if !utils.UUIDPattern.MatchString(args[0]) {
return fmt.Errorf("identity provider ID %q is not a UUID", args[0])
return errors.Errorf("identity provider ID %q is not a UUID", args[0])
}

return remove.Run(cmd.Context(), flags.ProjectRef, args[0], ssoOutput.Value)
Expand All @@ -81,7 +80,7 @@ var (
Example: ` supabase sso update b5ae62f9-ef1d-4f11-a02b-731c8bbb11e8 --project-ref mwjylndxudmiehsxhmmz --add-domains example.com`,
RunE: func(cmd *cobra.Command, args []string) error {
if !utils.UUIDPattern.MatchString(args[0]) {
return fmt.Errorf("identity provider ID %q is not a UUID", args[0])
return errors.Errorf("identity provider ID %q is not a UUID", args[0])
}

return update.Run(cmd.Context(), update.RunParams{
Expand All @@ -108,7 +107,7 @@ var (
Example: ` supabase sso show b5ae62f9-ef1d-4f11-a02b-731c8bbb11e8 --project-ref mwjylndxudmiehsxhmmz`,
RunE: func(cmd *cobra.Command, args []string) error {
if !utils.UUIDPattern.MatchString(args[0]) {
return fmt.Errorf("identity provider ID %q is not a UUID", args[0])
return errors.Errorf("identity provider ID %q is not a UUID", args[0])
}

format := ssoOutput.Value
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ require (
github.com/docker/cli v24.0.7+incompatible
github.com/docker/docker v24.0.7+incompatible
github.com/docker/go-connections v0.4.0
github.com/getsentry/sentry-go v0.25.0
github.com/go-errors/errors v1.5.1
github.com/go-git/go-git/v5 v5.11.0
github.com/go-xmlfmt/xmlfmt v1.1.2
github.com/golang-jwt/jwt/v5 v5.2.0
Expand Down Expand Up @@ -57,9 +59,7 @@ require (
github.com/fvbommel/sortorder v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/getkin/kin-openapi v0.118.0 // indirect
github.com/getsentry/sentry-go v0.25.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
Expand Down
10 changes: 1 addition & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ github.com/containers/common v0.57.1 h1:KWAs4PMPgBFmBV4QNbXhUB8TqvlgR95BJN2sbbXk
github.com/containers/common v0.57.1/go.mod h1:t/Z+/sFrapvFMEJe3YnecN49/Tae2wYEQShbEN6SRaU=
github.com/containers/storage v1.51.0 h1:AowbcpiWXzAjHosKz7MKvPEqpyX+ryZA/ZurytRrFNA=
github.com/containers/storage v1.51.0/go.mod h1:ybl8a3j1PPtpyaEi/5A6TOFs+5TrEyObeKJzVtkUlfc=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down Expand Up @@ -255,10 +254,6 @@ github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslC
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down Expand Up @@ -354,7 +349,6 @@ github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgSh
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down Expand Up @@ -408,7 +402,6 @@ github.com/microcosm-cc/bluemonday v1.0.25/go.mod h1:ZIOjCQp1OrzBBPIJmfX4qDYFuhU
github.com/miekg/pkcs11 v1.0.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU=
github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v0.0.0-20150613213606-2caf8efc9366/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
Expand Down Expand Up @@ -463,6 +456,7 @@ github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdU
github.com/perimeterx/marshmallow v1.1.4/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -640,7 +634,6 @@ golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand Down Expand Up @@ -789,7 +782,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
Expand Down
4 changes: 2 additions & 2 deletions internal/bans/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package get

import (
"context"
"errors"
"fmt"

"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/utils"
)
Expand All @@ -15,7 +15,7 @@ func Run(ctx context.Context, projectRef string, fsys afero.Fs) error {
{
resp, err := utils.GetSupabase().GetNetworkBansWithResponse(ctx, projectRef)
if err != nil {
return fmt.Errorf("failed to retrieve network bans: %w", err)
return errors.Errorf("failed to retrieve network bans: %w", err)
}
if resp.JSON201 == nil {
return errors.New("failed to retrieve network bans; received: " + string(resp.Body))
Expand Down
4 changes: 2 additions & 2 deletions internal/bans/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package update

import (
"context"
"errors"
"fmt"
"net"

"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/api"
Expand All @@ -15,7 +15,7 @@ func validateIps(ips []string) error {
for _, ip := range ips {
ip := net.ParseIP(ip)
if ip.To4() == nil {
return fmt.Errorf("only IPv4 supported at the moment: %s", ip)
return errors.Errorf("only IPv4 supported at the moment: %s", ip)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/db/branch/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package delete
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"path/filepath"

"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stdcopy"
"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/utils"
)
Expand Down Expand Up @@ -51,7 +51,7 @@ func deleteBranchDir(branch string, fsys afero.Fs) error {
}

if err := fsys.RemoveAll(branchPath); err != nil {
return fmt.Errorf("Failed deleting branch %s: %w", utils.Aqua(branch), err)
return errors.Errorf("Failed deleting branch %s: %w", utils.Aqua(branch), err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/db/diff/migra.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
_ "embed"
"errors"
"fmt"
"io"
"os"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat"
"github.com/go-errors/errors"
"github.com/jackc/pgconn"
"github.com/jackc/pgx/v4"
"github.com/spf13/afero"
Expand Down Expand Up @@ -151,7 +151,7 @@ func DiffSchemaMigra(ctx context.Context, source, target string, schema []string
&out,
&stderr,
); err != nil {
return "", fmt.Errorf("error diffing schema: %w:\n%s", err, stderr.String())
return "", errors.Errorf("error diffing schema: %w:\n%s", err, stderr.String())
}
return out.String(), nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/db/reset/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package reset
import (
"context"
_ "embed"
"errors"
"fmt"
"io"
"os"
Expand All @@ -16,6 +15,7 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/stdcopy"
"github.com/go-errors/errors"
"github.com/jackc/pgconn"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v4"
Expand Down Expand Up @@ -43,7 +43,7 @@ var (
func Run(ctx context.Context, version string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
if len(version) > 0 {
if _, err := strconv.Atoi(version); err != nil {
return repair.ErrInvalidVersion
return errors.New(repair.ErrInvalidVersion)
}
if _, err := repair.GetMigrationFile(version, fsys); err != nil {
return err
Expand Down Expand Up @@ -217,7 +217,7 @@ func restartServices(ctx context.Context) error {
services := []string{utils.StorageId, utils.GotrueId, utils.RealtimeId}
result := utils.WaitAll(services, func(id string) error {
if err := utils.Docker.ContainerRestart(ctx, id, container.StopOptions{}); err != nil && !errdefs.IsNotFound(err) {
return fmt.Errorf("Failed to restart %s: %w", id, err)
return errors.Errorf("Failed to restart %s: %w", id, err)
}
return nil
})
Expand Down Expand Up @@ -253,7 +253,7 @@ func WaitForServiceReady(ctx context.Context, started []string) error {
}
logs.Close()
}
return fmt.Errorf("%w: %v", ErrUnhealthy, started)
return errors.Errorf("%w: %v", ErrUnhealthy, started)
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/functions/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package download
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -14,6 +13,7 @@ import (

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/db/start"
"github.com/supabase/cli/internal/utils"
Expand Down Expand Up @@ -58,11 +58,11 @@ func getFunctionMetadata(ctx context.Context, projectRef, slug string) (*api.Fun

switch resp.StatusCode() {
case http.StatusNotFound:
return nil, errors.New("Function " + utils.Aqua(slug) + " does not exist on the Supabase project.")
return nil, errors.Errorf("Function %s does not exist on the Supabase project.", utils.Aqua(slug))
case http.StatusOK:
break
default:
return nil, errors.New("Failed to download Function " + utils.Aqua(slug) + " on the Supabase project: " + string(resp.Body))
return nil, errors.Errorf("Failed to download Function %s on the Supabase project: %s", utils.Aqua(slug), string(resp.Body))
}

if resp.JSON200.EntrypointPath == nil {
Expand Down Expand Up @@ -103,7 +103,7 @@ func downloadFunction(ctx context.Context, projectRef, slug, extractScriptPath s
cmd.Stdout = os.Stdout
cmd.Stderr = &errBuf
if err := cmd.Run(); err != nil {
return fmt.Errorf("Error downloading function: %w\n%v", err, errBuf.String())
return errors.Errorf("Error downloading function: %w\n%v", err, errBuf.String())
}
return nil
}
Expand Down
Loading

0 comments on commit a5308b4

Please sign in to comment.