From 82ea557dd37312af02b991069e2debb71721882b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 13 Aug 2023 20:49:30 +0800 Subject: [PATCH] Fix stderr usages (#26477) --- cmd/admin_user_create.go | 3 +-- models/migrations/migrations.go | 4 +--- services/gitdiff/gitdiff.go | 6 +++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cmd/admin_user_create.go b/cmd/admin_user_create.go index 260d729544..52ce46c353 100644 --- a/cmd/admin_user_create.go +++ b/cmd/admin_user_create.go @@ -6,7 +6,6 @@ package cmd import ( "errors" "fmt" - "os" auth_model "code.gitea.io/gitea/models/auth" user_model "code.gitea.io/gitea/models/user" @@ -87,7 +86,7 @@ func runCreateUser(c *cli.Context) error { username = c.String("username") } else { username = c.String("name") - fmt.Fprintf(os.Stderr, "--name flag is deprecated. Use --username instead.\n") + _, _ = fmt.Fprintf(c.App.ErrWriter, "--name flag is deprecated. Use --username instead.\n") } ctx, cancel := installSignals() diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index b2140a1eb1..55107439b0 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -7,7 +7,6 @@ package migrations import ( "context" "fmt" - "os" "code.gitea.io/gitea/models/migrations/v1_10" "code.gitea.io/gitea/models/migrations/v1_11" @@ -608,8 +607,7 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t if !setting.IsProd { msg += fmt.Sprintf("\nIf you are in development and really know what you're doing, you can force changing the migration version by executing: UPDATE version SET version=%d WHERE id=1;", minDBVersion+len(migrations)) } - _, _ = fmt.Fprintln(os.Stderr, msg) - log.Fatal(msg) + log.Fatal("Migration Error: %s", msg) return nil } diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 4cb2b1303d..4cc093e65d 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -13,7 +13,6 @@ import ( "html/template" "io" "net/url" - "os" "sort" "strings" "time" @@ -1152,14 +1151,15 @@ func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff }() go func() { + stderr := &bytes.Buffer{} cmdDiff.SetDescription(fmt.Sprintf("GetDiffRange [repo_path: %s]", repoPath)) if err := cmdDiff.Run(&git.RunOpts{ Timeout: time.Duration(setting.Git.Timeout.Default) * time.Second, Dir: repoPath, - Stderr: os.Stderr, Stdout: writer, + Stderr: stderr, }); err != nil { - log.Error("error during RunWithContext: %w", err) + log.Error("error during GetDiff(git diff dir: %s): %v, stderr: %s", repoPath, err, stderr.String()) } _ = writer.Close()