From 36b3f57b6167eb4e25d29dcb7be976d603f47d51 Mon Sep 17 00:00:00 2001 From: Jackson Owens Date: Fri, 6 Oct 2023 19:19:43 -0400 Subject: [PATCH] db: return structured errors from checkConsistency During Open, Pebble verifies the consistency between the Version and the object catalog. Previously if this function encountered an error or inconsistency, it would return a new error that erased the type(s) of the original errors. This commit modifies the function to use errors.Join and avoid the type erasure. This is necessary for the metamorphic test's error injection, which must be able to test an error to observe whether it is an errorfs.ErrInjected error. Informs #1115. --- open.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/open.go b/open.go index e021c9a1aa..83fa9dcfd5 100644 --- a/open.go +++ b/open.go @@ -1127,9 +1127,7 @@ func IsCorruptionError(err error) bool { } func checkConsistency(v *manifest.Version, dirname string, objProvider objstorage.Provider) error { - var buf bytes.Buffer - var args []interface{} - + var errs []error dedup := make(map[base.DiskFileNum]struct{}) for level, files := range v.Levels { iter := files.Iter() @@ -1153,22 +1151,18 @@ func checkConsistency(v *manifest.Version, dirname string, objProvider objstorag size, err = objProvider.Size(meta) } if err != nil { - buf.WriteString("L%d: %s: %v\n") - args = append(args, errors.Safe(level), errors.Safe(fileNum), err) + errs = append(errs, errors.Wrapf(err, "L%d: %s", errors.Safe(level), fileNum)) continue } if size != int64(fileSize) { - buf.WriteString("L%d: %s: object size mismatch (%s): %d (disk) != %d (MANIFEST)\n") - args = append(args, errors.Safe(level), errors.Safe(fileNum), objProvider.Path(meta), - errors.Safe(size), errors.Safe(fileSize)) + errs = append(errs, errors.Errorf( + "L%d: %s: object size mismatch (%s): %d (disk) != %d (MANIFEST)", + errors.Safe(level), fileNum, objProvider.Path(meta), + errors.Safe(size), errors.Safe(fileSize))) continue } } } - - if buf.Len() == 0 { - return nil - } - return errors.Errorf(buf.String(), args...) + return errors.Join(errs...) }