This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add database.NotFoundError helper type (#63671)
Use it in the 1 place it seemed obvious. I have other changes where it will be used in more places. This helps standardize our codebase. ## Test plan CI
- Loading branch information
1 parent
1ae58ee
commit eca5706
Showing
4 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package database | ||
|
||
// resourceNotFoundError is an error that indicates that a database resource was not found. It can be | ||
// returned by methods that get a single resource (such as Get or GetByXyz). | ||
// | ||
// errcode.IsNotFound(err) == true for notFoundError values. | ||
type resourceNotFoundError struct { | ||
noun string | ||
} | ||
|
||
func (e resourceNotFoundError) Error() string { | ||
const notFound = "not found" | ||
if e.noun == "" { | ||
return notFound | ||
} | ||
return e.noun + " " + notFound | ||
} | ||
|
||
func (resourceNotFoundError) NotFound() bool { return true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package database | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sourcegraph/sourcegraph/internal/errcode" | ||
) | ||
|
||
func TestResourceNotFoundError(t *testing.T) { | ||
err := resourceNotFoundError{"foo"} | ||
if want := "foo not found"; err.Error() != want { | ||
t.Errorf("got %q, want %q", err, want) | ||
} | ||
|
||
if !errcode.IsNotFound(resourceNotFoundError{"foo"}) { | ||
t.Fatal() | ||
} | ||
if !errcode.IsNotFound(&resourceNotFoundError{"foo"}) { | ||
t.Fatal() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters