From f026f61aaaa7b9e579e99f171f7fefb38c4c6181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Mon, 1 Oct 2018 23:27:34 +0200 Subject: [PATCH] bug: custom error for the different error case when loading a bug --- bug/bug.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bug/bug.go b/bug/bug.go index f29c04b4ae8cfa8b1bae9d850e6f642a849438dc..b6d09c50822169c62fe173866f449a6f06419238 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])