diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-08-28 14:42:23 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-08-29 13:03:54 +0300 |
commit | 00916ba2a6cd44954a1803c8a0dd34d7f5bf5a30 (patch) | |
tree | fbd54e858073d9466d82c8af51e06a85d4ff20ad /internal/gitaly/service/repository/apply_gitattributes.go | |
parent | 44f2b3fadd4689b6548bd55330c486264aaceb90 (diff) |
catfile: Refactor NotFoundError to match current best practices
The `catfile.NotFoundError` is not really following our current best
practices around error handling. It embeds a wrapped error that is the
same in all except one case, doesn't provide information about which
revision wasn't found and uses a `IsNotFound()` function instead of the
modern `errors.As()`. Last but not least, it's hard to construct this
error in dependents of this package, which is something we'll need in a
follow-up commit.
Refactor the error type to embed the revision that wasn't found instead
of an error such that we can attach structured error metadata to the
type. Furthermore, we convert all callsites to use `errors.As()` in
order to get rid of `IsNotFound()`.
Note that `catfile.GetTag()` abused this type by returning the error
with an embedded error effectively saying "object is not a tag". This
doesn't mean that the object wasn't found though, but instead indicates
that its type doesn't match our expectations, and thus using this error
is not a good fit. The function is converted to now use a plain error,
which is fine given than none of its callers actually checked whether
the returned error is of type `catfile.NotFoundError`.
Diffstat (limited to 'internal/gitaly/service/repository/apply_gitattributes.go')
-rw-r--r-- | internal/gitaly/service/repository/apply_gitattributes.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go index 9d97e9e71..131d961ee 100644 --- a/internal/gitaly/service/repository/apply_gitattributes.go +++ b/internal/gitaly/service/repository/apply_gitattributes.go @@ -37,7 +37,7 @@ func (s *server) applyGitattributes(ctx context.Context, repo *localrepo.Repo, o } blobObj, err := objectReader.Object(ctx, git.Revision(fmt.Sprintf("%s:.gitattributes", revision))) - if err != nil && !catfile.IsNotFound(err) { + if err != nil && !errors.As(err, &catfile.NotFoundError{}) { return err } @@ -46,7 +46,7 @@ func (s *server) applyGitattributes(ctx context.Context, repo *localrepo.Repo, o return err } - if catfile.IsNotFound(err) || blobObj.Type != "blob" { + if errors.As(err, &catfile.NotFoundError{}) || blobObj.Type != "blob" { locker, err := safe.NewLockingFileWriter(attributesPath, safe.LockingFileWriterConfig{ FileWriterConfig: safe.FileWriterConfig{FileMode: attributesFileMode}, }) |