error.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package gitutil
  5. import (
  6. "github.com/gogs/git-module"
  7. "github.com/pkg/errors"
  8. "gogs.io/gogs/internal/errutil"
  9. )
  10. var _ errutil.NotFound = (*Error)(nil)
  11. // Error is a wrapper of a Git error, which handles not found.
  12. type Error struct {
  13. error
  14. }
  15. func (e Error) NotFound() bool {
  16. return IsErrSubmoduleNotExist(e.error) ||
  17. IsErrRevisionNotExist(e.error)
  18. }
  19. // NewError wraps given error.
  20. func NewError(err error) error {
  21. return Error{error: err}
  22. }
  23. // IsErrSubmoduleNotExist returns true if the underlying error is
  24. // git.ErrSubmoduleNotExist.
  25. func IsErrSubmoduleNotExist(err error) bool {
  26. return errors.Cause(err) == git.ErrSubmoduleNotExist
  27. }
  28. // IsErrRevisionNotExist returns true if the underlying error is
  29. // git.ErrRevisionNotExist.
  30. func IsErrRevisionNotExist(err error) bool {
  31. return errors.Cause(err) == git.ErrRevisionNotExist
  32. }
  33. // IsErrNoMergeBase returns true if the underlying error is git.ErrNoMergeBase.
  34. func IsErrNoMergeBase(err error) bool {
  35. return errors.Cause(err) == git.ErrNoMergeBase
  36. }