Skip to content

Commit d2a0244

Browse files
authored
refactor: use errors.New instead of fmt.Errorf for non-format strings
2 parents 6f49abb + 74e2072 commit d2a0244

23 files changed

Lines changed: 82 additions & 64 deletions

internal/cmd/auth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"context"
55
_ "embed"
6+
"errors"
67
"fmt"
78
"net"
89
"net/http"
@@ -340,7 +341,7 @@ func (a authCallback) Result() (string, error) {
340341
return result, nil
341342
case <-time.After(5 * time.Minute):
342343
_ = a.server.Shutdown(context.Background())
343-
return "", fmt.Errorf("authentication timed out, try again")
344+
return "", errors.New("authentication timed out, try again")
344345
}
345346
}
346347

internal/cmd/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/spf13/cobra"
@@ -42,7 +43,7 @@ var configSetAutoUpdateCmd = &cobra.Command{
4243
RunE: func(cmd *cobra.Command, args []string) error {
4344
value := args[0]
4445
if value != "on" && value != "off" {
45-
return fmt.Errorf("autoupdate must be either 'on' or 'off'")
46+
return errors.New("autoupdate must be either 'on' or 'off'")
4647
}
4748

4849
cmd.SilenceUsage = true
@@ -75,7 +76,7 @@ var configSetTokenCmd = &cobra.Command{
7576

7677
token := args[0]
7778
if !isJwtTokenValid(token) {
78-
return fmt.Errorf("invalid token")
79+
return errors.New("invalid token")
7980
}
8081

8182
config.SetToken(token)

internal/cmd/db_generatetoken.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/spf13/cobra"
@@ -56,7 +57,7 @@ var dbGenerateTokenCmd = &cobra.Command{
5657
}
5758
token, err := getToken(client, database, expiration, flags.ReadOnly(), groupTokenFlag, claim)
5859
if err != nil {
59-
return fmt.Errorf("your database does not support token generation")
60+
return errors.New("your database does not support token generation")
6061
}
6162
fmt.Println(token)
6263
return nil
@@ -68,7 +69,7 @@ func getToken(client *turso.Client, database turso.Database, expiration string,
6869
return client.Databases.Token(database.Name, expiration, readOnly, claim)
6970
}
7071
if group && database.Group == "" {
71-
return "", fmt.Errorf("--group flag can only be set with group databases")
72+
return "", errors.New("--group flag can only be set with group databases")
7273
}
7374
return client.Groups.Token(database.Group, expiration, readOnly, claim)
7475
}

internal/cmd/db_import.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"fmt"
4+
"errors"
55
"path/filepath"
66
"strings"
77

@@ -24,7 +24,7 @@ var importCmd = &cobra.Command{
2424
RunE: func(cmd *cobra.Command, args []string) error {
2525
cmd.SilenceUsage = true
2626
if len(args) == 0 {
27-
return fmt.Errorf("filename is required: 'turso db import <filename>'")
27+
return errors.New("filename is required: 'turso db import <filename>'")
2828
}
2929
filename := args[0]
3030
fromFileFlag = filename

internal/cmd/db_inspect.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/dustin/go-humanize"
@@ -26,7 +27,7 @@ var dbInspectCmd = &cobra.Command{
2627
RunE: func(cmd *cobra.Command, args []string) error {
2728
name := args[0]
2829
if name == "" {
29-
return fmt.Errorf("please specify a database name")
30+
return errors.New("please specify a database name")
3031
}
3132
cmd.SilenceUsage = true
3233

internal/cmd/db_replicate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ var replicateCmd = &cobra.Command{
3434
}
3535
dbName := args[0]
3636
if dbName == "" {
37-
return fmt.Errorf("you must specify a database name to replicate it")
37+
return errors.New("you must specify a database name to replicate it")
3838
}
3939

4040
database, err := getDatabase(client, dbName, true)
4141
if err != nil {
4242
return err
4343
}
4444
if strings.HasPrefix(database.PrimaryRegion, "aws-") {
45-
return fmt.Errorf("replication is not available on AWS at the moment")
45+
return errors.New("replication is not available on AWS at the moment")
4646
}
4747

4848
location, err := getReplicateLocation(client, args, database)
@@ -174,7 +174,7 @@ func getReplicateLocation(client *turso.Client, args []string, database turso.Da
174174

175175
location := pickLocation(locations, database.Regions)
176176
if location == "" {
177-
return "", fmt.Errorf("you must specify a database location ID to replicate it")
177+
return "", errors.New("you must specify a database location ID to replicate it")
178178
}
179179

180180
return location, nil

internal/cmd/db_shell.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"bufio"
5+
"errors"
56
"fmt"
67
"io"
78
"net/http"
@@ -54,7 +55,7 @@ func getURL(db *turso.Database, client *turso.Client, http bool, primaryOnly boo
5455
}
5556
}
5657

57-
return "", fmt.Errorf("primary not found")
58+
return "", errors.New("primary not found")
5859
}
5960

6061
instances, err := client.Instances.List(db.Name)
@@ -73,7 +74,7 @@ func getURL(db *turso.Database, client *turso.Client, http bool, primaryOnly boo
7374
if instanceFlag != "" {
7475
return "", fmt.Errorf("instance %s for db %s not found", instanceFlag, db.Name)
7576
}
76-
return "", fmt.Errorf("impossible")
77+
return "", errors.New("impossible")
7778
}
7879

7980
func getDbURLForDump(u string) string {
@@ -93,7 +94,7 @@ var shellCmd = &cobra.Command{
9394
RunE: func(cmd *cobra.Command, args []string) error {
9495
nameOrUrl := args[0]
9596
if nameOrUrl == "" {
96-
return fmt.Errorf("please specify a database name")
97+
return errors.New("please specify a database name")
9798
}
9899
cmd.SilenceUsage = true
99100

@@ -106,7 +107,7 @@ var shellCmd = &cobra.Command{
106107
sql := ""
107108
if len(args) == 2 {
108109
if len(args[1]) == 0 {
109-
return fmt.Errorf("no SQL command to execute")
110+
return errors.New("no SQL command to execute")
110111
}
111112
if args[1] == ".dump" {
112113
isDump = true
@@ -176,7 +177,7 @@ var shellCmd = &cobra.Command{
176177
}
177178

178179
if countNonEmpty(authTokenSnake, authTokenCamel, jwt) > 1 {
179-
return fmt.Errorf("please use at most one of the following query parameters: 'auth_token', 'authToken', 'jwt'")
180+
return errors.New("please use at most one of the following query parameters: 'auth_token', 'authToken', 'jwt'")
180181
}
181182

182183
if authTokenSnake != "" {

internal/cmd/db_update.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/spf13/cobra"
@@ -65,7 +66,7 @@ func update(client *turso.Client, name string) error {
6566
version := db.Version
6667

6768
if err := client.Databases.Update(name, groupBoolFlag); err != nil {
68-
return fmt.Errorf("error updating database")
69+
return errors.New("error updating database")
6970
}
7071

7172
s.Stop()

internal/cmd/group.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56
"time"
67

@@ -104,7 +105,7 @@ var groupsCreateCmd = &cobra.Command{
104105
version := flags.Version()
105106
if canaryFlag {
106107
if version != "" {
107-
return fmt.Errorf("cannot specify both --canary and --version flags")
108+
return errors.New("cannot specify both --canary and --version flags")
108109
}
109110
version = "canary"
110111
}

internal/cmd/group_aws_migrate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"time"
78

@@ -30,7 +31,7 @@ var groupAwsMigrationInfoCmd = &cobra.Command{
3031
RunE: func(cmd *cobra.Command, args []string) error {
3132
group := args[0]
3233
if group == "" {
33-
return fmt.Errorf("the first argument must contain a group name")
34+
return errors.New("the first argument must contain a group name")
3435
}
3536

3637
cmd.SilenceUsage = true
@@ -71,7 +72,7 @@ var groupAwsMigrationStartCmd = &cobra.Command{
7172
RunE: func(cmd *cobra.Command, args []string) error {
7273
group := args[0]
7374
if group == "" {
74-
return fmt.Errorf("the first argument must contain a group name")
75+
return errors.New("the first argument must contain a group name")
7576
}
7677

7778
cmd.SilenceUsage = true
@@ -158,7 +159,7 @@ var groupAwsMigrationAbortCmd = &cobra.Command{
158159
RunE: func(cmd *cobra.Command, args []string) error {
159160
group := args[0]
160161
if group == "" {
161-
return fmt.Errorf("the first argument must contain a group name")
162+
return errors.New("the first argument must contain a group name")
162163
}
163164

164165
cmd.SilenceUsage = true

0 commit comments

Comments
 (0)