summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authordelvh <leon@kske.dev>2022-10-24 21:29:17 +0200
committerGitHub <noreply@github.com>2022-10-24 20:29:17 +0100
commit0ebb45cfe7606adf021ad359d6fbfcefc54360a5 (patch)
tree541b75d083213e93bbbfadbdc5d560c739543903 /cmd
parent7c11a73833f3aa9783015e5e13871d3c298d3ef6 (diff)
downloadgitea-0ebb45cfe7606adf021ad359d6fbfcefc54360a5.tar.gz
gitea-0ebb45cfe7606adf021ad359d6fbfcefc54360a5.zip
Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551)
Found using `find . -type f -name '*.go' -print -exec vim {} -c ':%s/fmt\.Errorf(\(.*\)%v\(.*\)err/fmt.Errorf(\1%w\2err/g' -c ':wq' \;` Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/admin.go4
-rw-r--r--cmd/cmd.go2
-rw-r--r--cmd/dump_repo.go2
-rw-r--r--cmd/embedded.go18
-rw-r--r--cmd/hook.go2
5 files changed, 14 insertions, 14 deletions
diff --git a/cmd/admin.go b/cmd/admin.go
index 2cf63d384a..525bc2cfcd 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -588,7 +588,7 @@ func runCreateUser(c *cli.Context) error {
}
if err := user_model.CreateUser(u, overwriteDefault); err != nil {
- return fmt.Errorf("CreateUser: %v", err)
+ return fmt.Errorf("CreateUser: %w", err)
}
if c.Bool("access-token") {
@@ -735,7 +735,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
Private: true,
})
if err != nil {
- return fmt.Errorf("SearchRepositoryByName: %v", err)
+ return fmt.Errorf("SearchRepositoryByName: %w", err)
}
if len(repos) == 0 {
break
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 36d54bb19f..f20a936325 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -68,7 +68,7 @@ Ensure you are running in the correct environment or set the correct configurati
If this is the intended configuration file complete the [database] section.`, setting.CustomConf)
}
if err := db.InitEngine(ctx); err != nil {
- return fmt.Errorf("unable to initialize the database using the configuration in %q. Error: %v", setting.CustomConf, err)
+ return fmt.Errorf("unable to initialize the database using the configuration in %q. Error: %w", setting.CustomConf, err)
}
return nil
}
diff --git a/cmd/dump_repo.go b/cmd/dump_repo.go
index 72456c61d3..5f41ab69a9 100644
--- a/cmd/dump_repo.go
+++ b/cmd/dump_repo.go
@@ -166,7 +166,7 @@ func runDumpRepository(ctx *cli.Context) error {
// make sure the directory doesn't exist or is empty, prevent from deleting user files
repoDir := ctx.String("repo_dir")
if exists, err := util.IsExist(repoDir); err != nil {
- return fmt.Errorf("unable to stat repo_dir %q: %v", repoDir, err)
+ return fmt.Errorf("unable to stat repo_dir %q: %w", repoDir, err)
} else if exists {
if isDir, _ := util.IsDir(repoDir); !isDir {
return fmt.Errorf("repo_dir %q already exists but it's not a directory", repoDir)
diff --git a/cmd/embedded.go b/cmd/embedded.go
index ffdc3d6a63..b71ee6dfe7 100644
--- a/cmd/embedded.go
+++ b/cmd/embedded.go
@@ -186,11 +186,11 @@ func runViewDo(c *cli.Context) error {
data, err := assets[0].Section.Asset(assets[0].Name)
if err != nil {
- return fmt.Errorf("%s: %v", assets[0].Path, err)
+ return fmt.Errorf("%s: %w", assets[0].Path, err)
}
if _, err = os.Stdout.Write(data); err != nil {
- return fmt.Errorf("%s: %v", assets[0].Path, err)
+ return fmt.Errorf("%s: %w", assets[0].Path, err)
}
return nil
@@ -251,11 +251,11 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
data, err := a.Section.Asset(a.Name)
if err != nil {
- return fmt.Errorf("%s: %v", a.Path, err)
+ return fmt.Errorf("%s: %w", a.Path, err)
}
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
- return fmt.Errorf("%s: %v", dir, err)
+ return fmt.Errorf("%s: %w", dir, err)
}
perms := os.ModePerm & 0o666
@@ -263,7 +263,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
fi, err := os.Lstat(dest)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
- return fmt.Errorf("%s: %v", dest, err)
+ return fmt.Errorf("%s: %w", dest, err)
}
} else if !overwrite && !rename {
fmt.Printf("%s already exists; skipped.\n", dest)
@@ -272,7 +272,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
return fmt.Errorf("%s already exists, but it's not a regular file", dest)
} else if rename {
if err := util.Rename(dest, dest+".bak"); err != nil {
- return fmt.Errorf("Error creating backup for %s: %v", dest, err)
+ return fmt.Errorf("Error creating backup for %s: %w", dest, err)
}
// Attempt to respect file permissions mask (even if user:group will be set anew)
perms = fi.Mode()
@@ -280,12 +280,12 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
file, err := os.OpenFile(dest, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, perms)
if err != nil {
- return fmt.Errorf("%s: %v", dest, err)
+ return fmt.Errorf("%s: %w", dest, err)
}
defer file.Close()
if _, err = file.Write(data); err != nil {
- return fmt.Errorf("%s: %v", dest, err)
+ return fmt.Errorf("%s: %w", dest, err)
}
fmt.Println(dest)
@@ -325,7 +325,7 @@ func getPatterns(args []string) ([]glob.Glob, error) {
pat := make([]glob.Glob, len(args))
for i := range args {
if g, err := glob.Compile(args[i], '/'); err != nil {
- return nil, fmt.Errorf("'%s': Invalid glob pattern: %v", args[i], err)
+ return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err)
} else {
pat[i] = g
}
diff --git a/cmd/hook.go b/cmd/hook.go
index ab6d48b545..3970d27cf2 100644
--- a/cmd/hook.go
+++ b/cmd/hook.go
@@ -312,7 +312,7 @@ func runHookPostReceive(c *cli.Context) error {
// First of all run update-server-info no matter what
if _, _, err := git.NewCommand(ctx, "update-server-info").RunStdString(nil); err != nil {
- return fmt.Errorf("Failed to call 'git update-server-info': %v", err)
+ return fmt.Errorf("Failed to call 'git update-server-info': %w", err)
}
// Now if we're an internal don't do anything else