aboutsummaryrefslogtreecommitdiffstats
path: root/bug/bug.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-10-01 23:27:34 +0200
committerMichael Muré <batolettre@gmail.com>2018-10-01 23:27:34 +0200
commitf026f61aaaa7b9e579e99f171f7fefb38c4c6181 (patch)
treeaf5964fd53d488acbafd53c6b55848366a89568b /bug/bug.go
parentaea85f04293210b94c6faa0ac9cb950a9239bd5b (diff)
downloadgit-bug-f026f61aaaa7b9e579e99f171f7fefb38c4c6181.tar.gz
bug: custom error for the different error case when loading a bug
Diffstat (limited to 'bug/bug.go')
-rw-r--r--bug/bug.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/bug/bug.go b/bug/bug.go
index f29c04b4..b6d09c50 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -29,6 +29,14 @@ const humanIdLength = 7
var ErrBugNotExist = errors.New("bug doesn't exist")
+type ErrMultipleMatch struct {
+ Matching []string
+}
+
+func (e ErrMultipleMatch) Error() string {
+ return fmt.Sprintf("Multiple matching bug found:\n%s", strings.Join(e.Matching, "\n"))
+}
+
var _ Interface = &Bug{}
// Bug hold the data of a bug thread, organized in a way close to
@@ -81,11 +89,11 @@ func FindLocalBug(repo repository.ClockedRepo, prefix string) (*Bug, error) {
}
if len(matching) == 0 {
- return nil, errors.New("No matching bug found.")
+ return nil, errors.New("no matching bug found.")
}
if len(matching) > 1 {
- return nil, fmt.Errorf("Multiple matching bug found:\n%s", strings.Join(matching, "\n"))
+ return nil, ErrMultipleMatch{Matching: matching}
}
return ReadLocalBug(repo, matching[0])