mirror of https://github.com/go-gitea/gitea.git
Backport #30313 by wxiaoguang `log.Xxx("%v")` is not ideal, this PR adds necessary context messages. Remove some unnecessary logs. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
a29e505c15
commit
5a6f7353d3
|
@ -114,7 +114,7 @@ func showWebStartupMessage(msg string) {
|
||||||
log.Info("* WorkPath: %s", setting.AppWorkPath)
|
log.Info("* WorkPath: %s", setting.AppWorkPath)
|
||||||
log.Info("* CustomPath: %s", setting.CustomPath)
|
log.Info("* CustomPath: %s", setting.CustomPath)
|
||||||
log.Info("* ConfigFile: %s", setting.CustomConf)
|
log.Info("* ConfigFile: %s", setting.CustomConf)
|
||||||
log.Info("%s", msg)
|
log.Info("%s", msg) // show startup message
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveInstall(ctx *cli.Context) error {
|
func serveInstall(ctx *cli.Context) error {
|
||||||
|
|
|
@ -76,23 +76,14 @@ func calcFingerprintNative(publicKeyContent string) (string, error) {
|
||||||
// CalcFingerprint calculate public key's fingerprint
|
// CalcFingerprint calculate public key's fingerprint
|
||||||
func CalcFingerprint(publicKeyContent string) (string, error) {
|
func CalcFingerprint(publicKeyContent string) (string, error) {
|
||||||
// Call the method based on configuration
|
// Call the method based on configuration
|
||||||
var (
|
useNative := setting.SSH.KeygenPath == ""
|
||||||
fnName, fp string
|
calcFn := util.Iif(useNative, calcFingerprintNative, calcFingerprintSSHKeygen)
|
||||||
err error
|
fp, err := calcFn(publicKeyContent)
|
||||||
)
|
|
||||||
if len(setting.SSH.KeygenPath) == 0 {
|
|
||||||
fnName = "calcFingerprintNative"
|
|
||||||
fp, err = calcFingerprintNative(publicKeyContent)
|
|
||||||
} else {
|
|
||||||
fnName = "calcFingerprintSSHKeygen"
|
|
||||||
fp, err = calcFingerprintSSHKeygen(publicKeyContent)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if IsErrKeyUnableVerify(err) {
|
if IsErrKeyUnableVerify(err) {
|
||||||
log.Info("%s", publicKeyContent)
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("%s: %w", fnName, err)
|
return "", fmt.Errorf("CalcFingerprint(%s): %w", util.Iif(useNative, "native", "ssh-keygen"), err)
|
||||||
}
|
}
|
||||||
return fp, nil
|
return fp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ func (repo *Repository) IsDependenciesEnabled(ctx context.Context) bool {
|
||||||
var u *RepoUnit
|
var u *RepoUnit
|
||||||
var err error
|
var err error
|
||||||
if u, err = repo.GetUnit(ctx, unit.TypeIssues); err != nil {
|
if u, err = repo.GetUnit(ctx, unit.TypeIssues); err != nil {
|
||||||
log.Trace("%s", err)
|
log.Trace("IsDependenciesEnabled: %v", err)
|
||||||
return setting.Service.DefaultEnableDependencies
|
return setting.Service.DefaultEnableDependencies
|
||||||
}
|
}
|
||||||
return u.IssuesConfig().EnableDependencies
|
return u.IssuesConfig().EnableDependencies
|
||||||
|
|
|
@ -214,7 +214,7 @@ func ToPointer[T any](val T) *T {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iif is an "inline-if", it returns "trueVal" if "condition" is true, otherwise "falseVal"
|
// Iif is an "inline-if", it returns "trueVal" if "condition" is true, otherwise "falseVal"
|
||||||
func Iif[T comparable](condition bool, trueVal, falseVal T) T {
|
func Iif[T any](condition bool, trueVal, falseVal T) T {
|
||||||
if condition {
|
if condition {
|
||||||
return trueVal
|
return trueVal
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
activities_model "code.gitea.io/gitea/models/activities"
|
activities_model "code.gitea.io/gitea/models/activities"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"code.gitea.io/gitea/modules/structs"
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/services/context"
|
"code.gitea.io/gitea/services/context"
|
||||||
"code.gitea.io/gitea/services/convert"
|
"code.gitea.io/gitea/services/convert"
|
||||||
|
@ -201,7 +200,6 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
||||||
if !ctx.FormBool("all") {
|
if !ctx.FormBool("all") {
|
||||||
statuses := ctx.FormStrings("status-types")
|
statuses := ctx.FormStrings("status-types")
|
||||||
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
|
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
|
||||||
log.Error("%v", opts.Status)
|
|
||||||
}
|
}
|
||||||
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -26,7 +26,7 @@ func GenerateActionsRunnerToken(ctx *context.PrivateContext) {
|
||||||
defer rd.Close()
|
defer rd.Close()
|
||||||
|
|
||||||
if err := json.NewDecoder(rd).Decode(&genRequest); err != nil {
|
if err := json.NewDecoder(rd).Decode(&genRequest); err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("JSON Decode failed: %v", err)
|
||||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
Err: err.Error(),
|
Err: err.Error(),
|
||||||
})
|
})
|
||||||
|
@ -35,7 +35,7 @@ func GenerateActionsRunnerToken(ctx *context.PrivateContext) {
|
||||||
|
|
||||||
owner, repo, err := parseScope(ctx, genRequest.Scope)
|
owner, repo, err := parseScope(ctx, genRequest.Scope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("parseScope failed: %v", err)
|
||||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
Err: err.Error(),
|
Err: err.Error(),
|
||||||
})
|
})
|
||||||
|
@ -45,18 +45,18 @@ func GenerateActionsRunnerToken(ctx *context.PrivateContext) {
|
||||||
if errors.Is(err, util.ErrNotExist) || (token != nil && !token.IsActive) {
|
if errors.Is(err, util.ErrNotExist) || (token != nil && !token.IsActive) {
|
||||||
token, err = actions_model.NewRunnerToken(ctx, owner, repo)
|
token, err = actions_model.NewRunnerToken(ctx, owner, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Sprintf("error while creating runner token: %v", err)
|
errMsg := fmt.Sprintf("error while creating runner token: %v", err)
|
||||||
log.Error("%v", err)
|
log.Error("NewRunnerToken failed: %v", errMsg)
|
||||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
Err: err,
|
Err: errMsg,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
err := fmt.Sprintf("could not get unactivated runner token: %v", err)
|
errMsg := fmt.Sprintf("could not get unactivated runner token: %v", err)
|
||||||
log.Error("%v", err)
|
log.Error("GetLatestRunnerToken failed: %v", errMsg)
|
||||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
Err: err,
|
Err: errMsg,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func verifyCommits(oldCommitID, newCommitID string, repo *git.Repository, env []
|
||||||
_ = stdoutWriter.Close()
|
_ = stdoutWriter.Close()
|
||||||
err := readAndVerifyCommitsFromShaReader(stdoutReader, repo, env)
|
err := readAndVerifyCommitsFromShaReader(stdoutReader, repo, env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("readAndVerifyCommitsFromShaReader failed: %v", err)
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
_ = stdoutReader.Close()
|
_ = stdoutReader.Close()
|
||||||
|
@ -66,7 +66,6 @@ func readAndVerifyCommitsFromShaReader(input io.ReadCloser, repo *git.Repository
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
err := readAndVerifyCommit(line, repo, env)
|
err := readAndVerifyCommit(line, repo, env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func SendEmail(ctx *context.PrivateContext) {
|
||||||
defer rd.Close()
|
defer rd.Close()
|
||||||
|
|
||||||
if err := json.NewDecoder(rd).Decode(&mail); err != nil {
|
if err := json.NewDecoder(rd).Decode(&mail); err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("JSON Decode failed: %v", err)
|
||||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
Err: err.Error(),
|
Err: err.Error(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -403,7 +403,6 @@ func EditUserPost(ctx *context.Context) {
|
||||||
ctx.Data["Err_Password"] = true
|
ctx.Data["Err_Password"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("auth.password_pwned"), tplUserEdit, &form)
|
ctx.RenderWithErr(ctx.Tr("auth.password_pwned"), tplUserEdit, &form)
|
||||||
case password.IsErrIsPwnedRequest(err):
|
case password.IsErrIsPwnedRequest(err):
|
||||||
log.Error("%s", err.Error())
|
|
||||||
ctx.Data["Err_Password"] = true
|
ctx.Data["Err_Password"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("auth.password_pwned_err"), tplUserEdit, &form)
|
ctx.RenderWithErr(ctx.Tr("auth.password_pwned_err"), tplUserEdit, &form)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -214,7 +214,6 @@ func ResetPasswdPost(ctx *context.Context) {
|
||||||
case errors.Is(err, password.ErrIsPwned):
|
case errors.Is(err, password.ErrIsPwned):
|
||||||
ctx.RenderWithErr(ctx.Tr("auth.password_pwned"), tplResetPassword, nil)
|
ctx.RenderWithErr(ctx.Tr("auth.password_pwned"), tplResetPassword, nil)
|
||||||
case password.IsErrIsPwnedRequest(err):
|
case password.IsErrIsPwnedRequest(err):
|
||||||
log.Error("%s", err.Error())
|
|
||||||
ctx.RenderWithErr(ctx.Tr("auth.password_pwned_err"), tplResetPassword, nil)
|
ctx.RenderWithErr(ctx.Tr("auth.password_pwned_err"), tplResetPassword, nil)
|
||||||
default:
|
default:
|
||||||
ctx.ServerError("UpdateAuth", err)
|
ctx.ServerError("UpdateAuth", err)
|
||||||
|
@ -298,7 +297,6 @@ func MustChangePasswordPost(ctx *context.Context) {
|
||||||
ctx.Data["Err_Password"] = true
|
ctx.Data["Err_Password"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("auth.password_pwned"), tplMustChangePassword, &form)
|
ctx.RenderWithErr(ctx.Tr("auth.password_pwned"), tplMustChangePassword, &form)
|
||||||
case password.IsErrIsPwnedRequest(err):
|
case password.IsErrIsPwnedRequest(err):
|
||||||
log.Error("%s", err.Error())
|
|
||||||
ctx.Data["Err_Password"] = true
|
ctx.Data["Err_Password"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("auth.password_pwned_err"), tplMustChangePassword, &form)
|
ctx.RenderWithErr(ctx.Tr("auth.password_pwned_err"), tplMustChangePassword, &form)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -74,7 +74,6 @@ func AccountPost(ctx *context.Context) {
|
||||||
case errors.Is(err, password.ErrIsPwned):
|
case errors.Is(err, password.ErrIsPwned):
|
||||||
ctx.Flash.Error(ctx.Tr("auth.password_pwned"))
|
ctx.Flash.Error(ctx.Tr("auth.password_pwned"))
|
||||||
case password.IsErrIsPwnedRequest(err):
|
case password.IsErrIsPwnedRequest(err):
|
||||||
log.Error("%s", err.Error())
|
|
||||||
ctx.Flash.Error(ctx.Tr("auth.password_pwned_err"))
|
ctx.Flash.Error(ctx.Tr("auth.password_pwned_err"))
|
||||||
default:
|
default:
|
||||||
ctx.ServerError("UpdateAuth", err)
|
ctx.ServerError("UpdateAuth", err)
|
||||||
|
|
|
@ -79,11 +79,11 @@ func VerifyCaptcha(ctx *Context, tpl base.TplName, form any) {
|
||||||
case setting.CfTurnstile:
|
case setting.CfTurnstile:
|
||||||
valid, err = turnstile.Verify(ctx, ctx.Req.Form.Get(cfTurnstileResponseField))
|
valid, err = turnstile.Verify(ctx, ctx.Req.Form.Get(cfTurnstileResponseField))
|
||||||
default:
|
default:
|
||||||
ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
|
ctx.ServerError("Unknown Captcha Type", fmt.Errorf("unknown Captcha Type: %s", setting.Service.CaptchaType))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("%v", err)
|
log.Debug("Captcha Verify failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !valid {
|
if !valid {
|
||||||
|
|
|
@ -91,7 +91,7 @@ func AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues
|
||||||
// NewPullRequest notifies new pull request to notifiers
|
// NewPullRequest notifies new pull request to notifiers
|
||||||
func NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
func NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
||||||
if err := pr.LoadIssue(ctx); err != nil {
|
if err := pr.LoadIssue(ctx); err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("LoadIssue failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := pr.Issue.LoadPoster(ctx); err != nil {
|
if err := pr.Issue.LoadPoster(ctx); err != nil {
|
||||||
|
@ -112,7 +112,7 @@ func PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *iss
|
||||||
// PullRequestReview notifies new pull request review
|
// PullRequestReview notifies new pull request review
|
||||||
func PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
func PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||||
if err := review.LoadReviewer(ctx); err != nil {
|
if err := review.LoadReviewer(ctx); err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("LoadReviewer failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, notifier := range notifiers {
|
for _, notifier := range notifiers {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod
|
||||||
|
|
||||||
t, err := NewTemporaryUploadRepository(ctx, repo)
|
t, err := NewTemporaryUploadRepository(ctx, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("NewTemporaryUploadRepository failed: %v", err)
|
||||||
}
|
}
|
||||||
defer t.Close()
|
defer t.Close()
|
||||||
if err := t.Clone(opts.OldBranch, false); err != nil {
|
if err := t.Clone(opts.OldBranch, false); err != nil {
|
||||||
|
|
|
@ -111,7 +111,7 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user
|
||||||
|
|
||||||
t, err := NewTemporaryUploadRepository(ctx, repo)
|
t, err := NewTemporaryUploadRepository(ctx, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("NewTemporaryUploadRepository failed: %v", err)
|
||||||
}
|
}
|
||||||
defer t.Close()
|
defer t.Close()
|
||||||
if err := t.Clone(opts.OldBranch, true); err != nil {
|
if err := t.Clone(opts.OldBranch, true); err != nil {
|
||||||
|
|
|
@ -143,7 +143,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
|
||||||
|
|
||||||
t, err := NewTemporaryUploadRepository(ctx, repo)
|
t, err := NewTemporaryUploadRepository(ctx, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("NewTemporaryUploadRepository failed: %v", err)
|
||||||
}
|
}
|
||||||
defer t.Close()
|
defer t.Close()
|
||||||
hasOldBranch := true
|
hasOldBranch := true
|
||||||
|
|
|
@ -161,7 +161,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||||
if isOldWikiExist {
|
if isOldWikiExist {
|
||||||
err := gitRepo.RemoveFilesFromIndex(oldWikiPath)
|
err := gitRepo.RemoveFilesFromIndex(oldWikiPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("RemoveFilesFromIndex failed: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,18 +171,18 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||||
|
|
||||||
objectHash, err := gitRepo.HashObject(strings.NewReader(content))
|
objectHash, err := gitRepo.HashObject(strings.NewReader(content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("HashObject failed: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gitRepo.AddObjectToIndex("100644", objectHash, newWikiPath); err != nil {
|
if err := gitRepo.AddObjectToIndex("100644", objectHash, newWikiPath); err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("AddObjectToIndex failed: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tree, err := gitRepo.WriteTree()
|
tree, err := gitRepo.WriteTree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("WriteTree failed: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||||
|
|
||||||
commitHash, err := gitRepo.CommitTree(doer.NewGitSig(), committer, tree, commitTreeOpts)
|
commitHash, err := gitRepo.CommitTree(doer.NewGitSig(), committer, tree, commitTreeOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("CommitTree failed: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,11 +222,11 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("Push failed: %v", err)
|
||||||
if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
|
if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Push: %w", err)
|
return fmt.Errorf("failed to push: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue