diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-07-05 16:22:05 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-07-06 14:03:20 +0300 |
commit | 9b583f8f1802e130ec874558050502014db8f491 (patch) | |
tree | a94e4fc2e5a742bc3ee3ccb7b45b848e7ba8d585 | |
parent | 50a10cb0861e9349fef0d979cee87a8d7f7c3af4 (diff) |
updateref: Convert `NonExistentObjectError` to use error metadata
Convert the `NonExistentObjectError` to use error metadata instead
of embedding the information into the error message.
-rw-r--r-- | internal/git/updateref/updateref.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go index 5db4b35fb..3c4815c22 100644 --- a/internal/git/updateref/updateref.go +++ b/internal/git/updateref/updateref.go @@ -105,7 +105,16 @@ type NonExistentObjectError struct { } func (e NonExistentObjectError) Error() string { - return fmt.Sprintf("pointed reference %q to a non-existent object %q", e.ReferenceName, e.ObjectID) + return "target object missing" +} + +// ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides the missing object as well as the +// reference that should have been updated to point to it. +func (e NonExistentObjectError) ErrorMetadata() []structerr.MetadataItem { + return []structerr.MetadataItem{ + {Key: "reference", Value: e.ReferenceName}, + {Key: "missing_object", Value: e.ObjectID}, + } } // NonCommitObjectError is returned when attempting to point a branch to an object that is not an object. |