diff options
Diffstat (limited to 'internal/gitutil/error.go')
-rw-r--r-- | internal/gitutil/error.go | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/internal/gitutil/error.go b/internal/gitutil/error.go index d8023f94..20aa3b51 100644 --- a/internal/gitutil/error.go +++ b/internal/gitutil/error.go @@ -6,8 +6,33 @@ package gitutil import ( "github.com/gogs/git-module" + + "gogs.io/gogs/internal/errutil" ) +var _ errutil.NotFound = (*Error)(nil) + +// Error is a wrapper of a Git error, which handles not found. +type Error struct { + error +} + +func (e Error) NotFound() bool { + return IsErrSubmoduleNotExist(e.error) || + IsErrRevisionNotExist(e.error) + +} + +// NewError wraps given error. +func NewError(err error) error { + return Error{error: err} +} + +// IsErrSubmoduleNotExist returns true if the error is git.ErrSubmoduleNotExist. +func IsErrSubmoduleNotExist(err error) bool { + return err == git.ErrSubmoduleNotExist +} + // IsErrRevisionNotExist returns true if the error is git.ErrRevisionNotExist. func IsErrRevisionNotExist(err error) bool { return err == git.ErrRevisionNotExist @@ -17,8 +42,3 @@ func IsErrRevisionNotExist(err error) bool { func IsErrNoMergeBase(err error) bool { return err == git.ErrNoMergeBase } - -// IsErrSubmoduleNotExist returns true if the error is git.ErrSubmoduleNotExist. -func IsErrSubmoduleNotExist(err error) bool { - return err == git.ErrSubmoduleNotExist -} |