Przeglądaj źródła

all: Clean up fmt.Errorf usage (#8309)

greatroar 3 lat temu
rodzic
commit
49488c0e71

+ 3 - 2
cmd/syncthing/cli/operations.go

@@ -8,6 +8,7 @@ package cli
 
 import (
 	"bufio"
+	"errors"
 	"fmt"
 	"path/filepath"
 
@@ -77,12 +78,12 @@ func foldersOverride(c *cli.Context) error {
 				if body != "" {
 					errStr += "\nBody: " + body
 				}
-				return fmt.Errorf(errStr)
+				return errors.New(errStr)
 			}
 			return nil
 		}
 	}
-	return fmt.Errorf("Folder " + rid + " not found")
+	return fmt.Errorf("Folder %q not found", rid)
 }
 
 func setDefaultIgnores(c *cli.Context) error {

+ 4 - 3
cmd/syncthing/decrypt/decrypt.go

@@ -10,6 +10,7 @@ package decrypt
 import (
 	"encoding/binary"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"io"
 	"log"
@@ -45,7 +46,7 @@ func (c *CLI) Run() error {
 	log.SetFlags(0)
 
 	if c.To == "" && !c.VerifyOnly {
-		return fmt.Errorf("must set --to or --verify-only")
+		return errors.New("must set --to or --verify-only")
 	}
 
 	if c.TokenPath == "" {
@@ -138,7 +139,7 @@ func (c *CLI) process(srcFs fs.Filesystem, dstFs fs.Filesystem, path string) err
 	}
 	defer encFd.Close()
 
-	encFi, err := c.loadEncryptedFileInfo(encFd)
+	encFi, err := loadEncryptedFileInfo(encFd)
 	if err != nil {
 		return fmt.Errorf("%s: loading metadata trailer: %w", path, err)
 	}
@@ -246,7 +247,7 @@ func (c *CLI) decryptFile(encFi *protocol.FileInfo, plainFi *protocol.FileInfo,
 
 // loadEncryptedFileInfo loads the encrypted FileInfo trailer from a file on
 // disk.
-func (c *CLI) loadEncryptedFileInfo(fd fs.File) (*protocol.FileInfo, error) {
+func loadEncryptedFileInfo(fd fs.File) (*protocol.FileInfo, error) {
 	// Seek to the size of the trailer block
 	if _, err := fd.Seek(-4, io.SeekEnd); err != nil {
 		return nil, err

+ 2 - 1
cmd/syncthing/generate/generate.go

@@ -11,6 +11,7 @@ import (
 	"bufio"
 	"context"
 	"crypto/tls"
+	"errors"
 	"fmt"
 	"log"
 	"os"
@@ -40,7 +41,7 @@ func (c *CLI) Run() error {
 
 	if c.HomeDir != "" {
 		if c.ConfDir != "" {
-			return fmt.Errorf("--home must not be used together with --config")
+			return errors.New("--home must not be used together with --config")
 		}
 		c.ConfDir = c.HomeDir
 	}

+ 2 - 2
lib/protocol/deviceid.go

@@ -45,7 +45,7 @@ func DeviceIDFromString(s string) (DeviceID, error) {
 func DeviceIDFromBytes(bs []byte) (DeviceID, error) {
 	var n DeviceID
 	if len(bs) != len(n) {
-		return n, fmt.Errorf("incorrect length of byte slice representing device ID")
+		return n, errors.New("incorrect length of byte slice representing device ID")
 	}
 	copy(n[:], bs)
 	return n, nil
@@ -129,7 +129,7 @@ func (n *DeviceID) UnmarshalText(bs []byte) error {
 	}
 }
 
-func (n *DeviceID) ProtoSize() int {
+func (*DeviceID) ProtoSize() int {
 	// Used by protobuf marshaller.
 	return DeviceIDLength
 }