2
0

error.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "gogs.io/gogs/internal/errutil"
  8. )
  9. var _ errutil.NotFound = (*Error)(nil)
  10. // Error is a wrapper of a Git error, which handles not found.
  11. type Error struct {
  12. error
  13. }
  14. func (e Error) NotFound() bool {
  15. return IsErrSubmoduleNotExist(e.error) ||
  16. IsErrRevisionNotExist(e.error)
  17. }
  18. // NewError wraps given error.
  19. func NewError(err error) error {
  20. return Error{error: err}
  21. }
  22. // IsErrSubmoduleNotExist returns true if the error is git.ErrSubmoduleNotExist.
  23. func IsErrSubmoduleNotExist(err error) bool {
  24. return err == git.ErrSubmoduleNotExist
  25. }
  26. // IsErrRevisionNotExist returns true if the error is git.ErrRevisionNotExist.
  27. func IsErrRevisionNotExist(err error) bool {
  28. return err == git.ErrRevisionNotExist
  29. }
  30. // IsErrNoMergeBase returns true if the error is git.ErrNoMergeBase.
  31. func IsErrNoMergeBase(err error) bool {
  32. return err == git.ErrNoMergeBase
  33. }