Use generic typed error pattern
The codebase doesn't yet use the explicitly typed error pattern. To keep things consistent, lets use the generic error type.
This commit is contained in:
parent
1b4902f196
commit
68db934507
@ -90,12 +90,6 @@ 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 {
|
||||
@ -103,7 +97,7 @@ func GetBookmark(bookmarkPath string, bookmarkName string) (Bookmark, error) {
|
||||
}
|
||||
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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user