Fix stderr usages (#26477)

This commit is contained in:
wxiaoguang 2023-08-13 20:49:30 +08:00 committed by GitHub
parent ca74b074ea
commit 82ea557dd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 8 deletions

View file

@ -6,7 +6,6 @@ package cmd
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
@ -87,7 +86,7 @@ func runCreateUser(c *cli.Context) error {
username = c.String("username") username = c.String("username")
} else { } else {
username = c.String("name") 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() ctx, cancel := installSignals()

View file

@ -7,7 +7,6 @@ package migrations
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"code.gitea.io/gitea/models/migrations/v1_10" "code.gitea.io/gitea/models/migrations/v1_10"
"code.gitea.io/gitea/models/migrations/v1_11" "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 { 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)) 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("Migration Error: %s", msg)
log.Fatal(msg)
return nil return nil
} }

View file

@ -13,7 +13,6 @@ import (
"html/template" "html/template"
"io" "io"
"net/url" "net/url"
"os"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -1152,14 +1151,15 @@ func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff
}() }()
go func() { go func() {
stderr := &bytes.Buffer{}
cmdDiff.SetDescription(fmt.Sprintf("GetDiffRange [repo_path: %s]", repoPath)) cmdDiff.SetDescription(fmt.Sprintf("GetDiffRange [repo_path: %s]", repoPath))
if err := cmdDiff.Run(&git.RunOpts{ if err := cmdDiff.Run(&git.RunOpts{
Timeout: time.Duration(setting.Git.Timeout.Default) * time.Second, Timeout: time.Duration(setting.Git.Timeout.Default) * time.Second,
Dir: repoPath, Dir: repoPath,
Stderr: os.Stderr,
Stdout: writer, Stdout: writer,
Stderr: stderr,
}); err != nil { }); 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() _ = writer.Close()