aboutsummaryrefslogtreecommitdiffstats
path: root/remote.go
diff options
context:
space:
mode:
authorandrew2nelson <andrew2nelson@arista.com>2020-09-02 13:38:42 -0700
committerandrew2nelson <andrew2nelson@arista.com>2020-09-02 13:45:28 -0700
commit9d7bd4d4bded83428a39dda358eef19e98e42f23 (patch)
treee21f7e24a11118e2f8eda4884ddcb1cdff030144 /remote.go
parent6da5e5958ecc0e6f8da6ee2b6714e50b8ef26df4 (diff)
downloadgo-git-9d7bd4d4bded83428a39dda358eef19e98e42f23.tar.gz
Fetch should return a unique error type when ref not found
It can be useful for callers to distinguish between an error of "couldn't find remote ref" and some other error like "network error". Creating an explicit error type for this allows consumers to determine the kind of error using the errors.Is and errors.As interface added in go1.13
Diffstat (limited to 'remote.go')
-rw-r--r--remote.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/remote.go b/remote.go
index 89b3051..d88e8e6 100644
--- a/remote.go
+++ b/remote.go
@@ -32,6 +32,19 @@ var (
ErrExactSHA1NotSupported = errors.New("server does not support exact SHA1 refspec")
)
+type NoMatchingRefSpecError struct {
+ refSpec config.RefSpec
+}
+
+func (e NoMatchingRefSpecError) Error() string {
+ return fmt.Sprintf("couldn't find remote ref %q", e.refSpec.Src())
+}
+
+func (e NoMatchingRefSpecError) Is(target error) bool {
+ _, ok := target.(NoMatchingRefSpecError)
+ return ok
+}
+
const (
// This describes the maximum number of commits to walk when
// computing the haves to send to a server, for each ref in the
@@ -751,7 +764,7 @@ func doCalculateRefs(
})
if !matched && !s.IsWildcard() {
- return fmt.Errorf("couldn't find remote ref %q", s.Src())
+ return NoMatchingRefSpecError{refSpec: s}
}
return err