Skip to content

Commit

Permalink
Use generic typed error pattern
Browse files Browse the repository at this point in the history
The codebase doesn't yet use the explicitly typed error pattern. To keep
things consistent, lets use the generic error type.
  • Loading branch information
akarki15 committed Nov 12, 2016
1 parent 1b4902f commit 68db934
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
8 changes: 1 addition & 7 deletions pkg/bookmarks/bookmarks.go
Expand Up @@ -90,20 +90,14 @@ func ReadAll(path string) (map[string]Bookmark, error) {
return results, nil
}

type ErrNonExistingBookmark string

func (e ErrNonExistingBookmark) Error() string {
return fmt.Sprintf("couldn't find a bookmark with name %s", e)
}

func GetBookmark(bookmarkPath string, bookmarkName string) (Bookmark, error) {
bookmarks, err := ReadAll(bookmarkPath)
if err != nil {
return Bookmark{}, err
}
bookmark, ok := bookmarks[bookmarkName]
if !ok {
return Bookmark{}, ErrNonExistingBookmark(bookmarkName)
return Bookmark{}, fmt.Errorf("couldn't find a bookmark with name %s", bookmarkName)
}
return bookmark, nil

Expand Down
3 changes: 2 additions & 1 deletion pkg/bookmarks/bookmarks_test.go
Expand Up @@ -84,7 +84,8 @@ func Test_GetBookmark(t *testing.T) {
}

_, err = GetBookmark("../../data", "bar")
assert.Equal(t, ErrNonExistingBookmark("bar"), err)
expErrStr := "couldn't find a bookmark with name bar"
assert.Equal(t, expErrStr, err.Error())

_, err = GetBookmark("foo", "bookmark")
assert.Error(t, err)
Expand Down

0 comments on commit 68db934

Please sign in to comment.