aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-11-02 19:20:22 +0800
committerGitHub <noreply@github.com>2024-11-02 11:20:22 +0000
commite524f63d58900557d7d57fc3bcd19d9facc8b8ee (patch)
tree205126f1134cce89b2a19faff2f1cfc48ad61adb /modules
parent13a203828c40f9ad1005b16b4ae26256a7df8263 (diff)
downloadgitea-e524f63d58900557d7d57fc3bcd19d9facc8b8ee.tar.gz
gitea-e524f63d58900557d7d57fc3bcd19d9facc8b8ee.zip
Fix git error handling (#32401)
Diffstat (limited to 'modules')
-rw-r--r--modules/git/error.go40
-rw-r--r--modules/git/repo_attribute.go4
2 files changed, 10 insertions, 34 deletions
diff --git a/modules/git/error.go b/modules/git/error.go
index 91d25eca69..10fb37be07 100644
--- a/modules/git/error.go
+++ b/modules/git/error.go
@@ -4,28 +4,14 @@
package git
import (
+ "context"
+ "errors"
"fmt"
"strings"
- "time"
"code.gitea.io/gitea/modules/util"
)
-// ErrExecTimeout error when exec timed out
-type ErrExecTimeout struct {
- Duration time.Duration
-}
-
-// IsErrExecTimeout if some error is ErrExecTimeout
-func IsErrExecTimeout(err error) bool {
- _, ok := err.(ErrExecTimeout)
- return ok
-}
-
-func (err ErrExecTimeout) Error() string {
- return fmt.Sprintf("execution is timeout [duration: %v]", err.Duration)
-}
-
// ErrNotExist commit not exist error
type ErrNotExist struct {
ID string
@@ -62,21 +48,6 @@ func IsErrBadLink(err error) bool {
return ok
}
-// ErrUnsupportedVersion error when required git version not matched
-type ErrUnsupportedVersion struct {
- Required string
-}
-
-// IsErrUnsupportedVersion if some error is ErrUnsupportedVersion
-func IsErrUnsupportedVersion(err error) bool {
- _, ok := err.(ErrUnsupportedVersion)
- return ok
-}
-
-func (err ErrUnsupportedVersion) Error() string {
- return fmt.Sprintf("Operation requires higher version [required: %s]", err.Required)
-}
-
// ErrBranchNotExist represents a "BranchNotExist" kind of error.
type ErrBranchNotExist struct {
Name string
@@ -185,3 +156,10 @@ func IsErrMoreThanOne(err error) bool {
func (err *ErrMoreThanOne) Error() string {
return fmt.Sprintf("ErrMoreThanOne Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut)
}
+
+func IsErrCanceledOrKilled(err error) bool {
+ // When "cancel()" a git command's context, the returned error of "Run()" could be one of them:
+ // - context.Canceled
+ // - *exec.ExitError: "signal: killed"
+ return err != nil && (errors.Is(err, context.Canceled) || err.Error() == "signal: killed")
+}
diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go
index 84f85d1b1a..90eb783fe8 100644
--- a/modules/git/repo_attribute.go
+++ b/modules/git/repo_attribute.go
@@ -166,9 +166,7 @@ func (c *CheckAttributeReader) Run() error {
Stdout: c.stdOut,
Stderr: stdErr,
})
- if err != nil && // If there is an error we need to return but:
- c.ctx.Err() != err && // 1. Ignore the context error if the context is cancelled or exceeds the deadline (RunWithContext could return c.ctx.Err() which is Canceled or DeadlineExceeded)
- err.Error() != "signal: killed" { // 2. We should not pass up errors due to the program being killed
+ if err != nil && !IsErrCanceledOrKilled(err) {
return fmt.Errorf("failed to run attr-check. Error: %w\nStderr: %s", err, stdErr.String())
}
return nil