diff options
author | Michael Muré <batolettre@gmail.com> | 2018-10-01 23:27:34 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-10-01 23:27:34 +0200 |
commit | f026f61aaaa7b9e579e99f171f7fefb38c4c6181 (patch) | |
tree | af5964fd53d488acbafd53c6b55848366a89568b | |
parent | aea85f04293210b94c6faa0ac9cb950a9239bd5b (diff) | |
download | git-bug-f026f61aaaa7b9e579e99f171f7fefb38c4c6181.tar.gz |
bug: custom error for the different error case when loading a bug
-rw-r--r-- | bug/bug.go | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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]) |