Skip to content

Commit

Permalink
chore: Reduce use of fmt.Sprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 9, 2024
1 parent 8921b78 commit cc6844a
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/chezmoi/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (e UnknownArchiveFormatError) Error() string {
if e == UnknownArchiveFormatError(ArchiveFormatUnknown) {
return "unknown archive format"
}
return fmt.Sprintf("%s: unknown archive format", string(e))
return string(e) + ": unknown archive format"
}

// An WalkArchiveFunc is called once for each entry in an archive.
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/addcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *Config) defaultPreAddFunc(targetRelPath chezmoi.RelPath) error {
case choice == "yes":
return nil
default:
panic(fmt.Sprintf("%s: unexpected choice", choice))
panic(choice + ": unexpected choice")
}
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (c *Config) defaultReplaceFunc(
case choice == "yes":
return nil
default:
panic(fmt.Sprintf("%s: unexpected choice", choice))
panic(choice + ": unexpected choice")
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/azurekeyvaulttemplatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"errors"
"fmt"

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (c *Config) azureKeyVaultTemplateFunc(args ...string) string {
switch len(args) {
case 1:
if c.AzureKeyVault.DefaultVault == "" {
panic(fmt.Errorf("no value set in azureKeyVault.defaultVault"))
panic(errors.New("no value set in azureKeyVault.defaultVault"))
}
secretName, vaultName = args[0], c.AzureKeyVault.DefaultVault
case 2:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func markPersistentFlagsRequired(cmd *cobra.Command, flags ...string) {
func mustLongHelp(command string) string {
help, ok := helps[command]
if !ok {
panic(fmt.Sprintf("missing long help for command %s", command))
panic(command + ": missing long help")
}
return help.longHelp
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (c *Config) Close() error {
// same key.
func (c *Config) addTemplateFunc(key string, value any) {
if _, ok := c.templateFuncs[key]; ok {
panic(fmt.Sprintf("%s: already defined", key))
panic(key + ": already defined")
}
c.templateFuncs[key] = value
}
Expand Down Expand Up @@ -981,7 +981,7 @@ func (c *Config) defaultPreApplyFunc(
case choice == "quit":
return chezmoi.ExitCodeError(0)
default:
panic(fmt.Sprintf("%s: unexpected choice", choice))
panic(choice + ": unexpected choice")
}
}
}
Expand Down Expand Up @@ -1023,7 +1023,7 @@ func (c *Config) defaultPreApplyFunc(
case choice == "quit":
return chezmoi.ExitCodeError(0)
default:
panic(fmt.Sprintf("%s: unexpected choice", choice))
panic(choice + ": unexpected choice")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/doctorcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (c *binaryCheck) Run(system chezmoi.System, homeDirAbsPath chezmoi.AbsPath)
var pathAbsPath chezmoi.AbsPath
switch path, err := chezmoi.LookPath(c.binaryname); {
case errors.Is(err, exec.ErrNotFound):
return c.ifNotExist, fmt.Sprintf("%s not found in $PATH", c.binaryname)
return c.ifNotExist, c.binaryname + " not found in $PATH"
case err != nil:
return checkResultFailed, err.Error()
default:
Expand Down Expand Up @@ -551,7 +551,7 @@ func (c *configFileCheck) Run(system chezmoi.System, homeDirAbsPath chezmoi.AbsP
filenameStrs = append(filenameStrs, filenameAbsPath.String())
}
sort.Strings(filenameStrs)
return checkResultWarning, fmt.Sprintf("%s: multiple config files", englishList(filenameStrs))
return checkResultWarning, englishList(filenameStrs) + ": multiple config files"
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/readdcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ TARGET_REL_PATH:
case choice == "quit":
return chezmoi.ExitCodeError(0)
default:
panic(fmt.Sprintf("%s: unexpected choice", choice))
panic(choice + ": unexpected choice")
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/statuscmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"io/fs"
"strings"
Expand Down Expand Up @@ -81,9 +82,9 @@ func (c *Config) runStatusCmd(cmd *cobra.Command, args []string) error {
case chezmoi.PathStyleRelative:
path = targetRelPath.String()
case chezmoi.PathStyleSourceAbsolute:
return fmt.Errorf("source-absolute not supported for status")
return errors.New("source-absolute not supported for status")
case chezmoi.PathStyleSourceRelative:
return fmt.Errorf("source-relative not supported for status")
return errors.New("source-relative not supported for status")
}

fmt.Fprintf(&builder, "%c%c %s\n", x, y, path)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmds/execute-template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func run() error {
}

if flag.NArg() == 0 {
return fmt.Errorf("no arguments")
return errors.New("no arguments")
}

templateName := path.Base(flag.Arg(0))
Expand Down
3 changes: 1 addition & 2 deletions internal/git/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package git
import (
"bufio"
"bytes"
"fmt"
"regexp"
"strconv"
)
Expand Down Expand Up @@ -127,7 +126,7 @@ var (
)

func (e ParseError) Error() string {
return fmt.Sprintf("%s: parse error", string(e))
return string(e) + ": parse error"
}

// ParseStatusPorcelainV2 parses the output of
Expand Down

0 comments on commit cc6844a

Please sign in to comment.