error.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package gitutil
  2. import (
  3. "github.com/cockroachdb/errors"
  4. "github.com/gogs/git-module"
  5. "gogs.io/gogs/internal/errutil"
  6. )
  7. var _ errutil.NotFound = (*Error)(nil)
  8. // Error is a wrapper of a Git error, which handles not found.
  9. type Error struct {
  10. error
  11. }
  12. func (e Error) NotFound() bool {
  13. return IsErrSubmoduleNotExist(e.error) ||
  14. IsErrRevisionNotExist(e.error)
  15. }
  16. // NewError wraps given error.
  17. func NewError(err error) error {
  18. return Error{error: err}
  19. }
  20. // IsErrSubmoduleNotExist returns true if the underlying error is
  21. // git.ErrSubmoduleNotExist.
  22. func IsErrSubmoduleNotExist(err error) bool {
  23. return errors.Cause(err) == git.ErrSubmoduleNotExist
  24. }
  25. // IsErrRevisionNotExist returns true if the underlying error is
  26. // git.ErrRevisionNotExist.
  27. func IsErrRevisionNotExist(err error) bool {
  28. return errors.Cause(err) == git.ErrRevisionNotExist
  29. }
  30. // IsErrNoMergeBase returns true if the underlying error is git.ErrNoMergeBase.
  31. func IsErrNoMergeBase(err error) bool {
  32. return errors.Cause(err) == git.ErrNoMergeBase
  33. }