Skip to content

Commit

Permalink
Fix stderr usages (#26477)
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang authored Aug 13, 2023
1 parent ca74b07 commit 82ea557
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions cmd/admin_user_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions services/gitdiff/gitdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"html/template"
"io"
"net/url"
"os"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 82ea557

Please sign in to comment.