LCOV - code coverage report
Current view: top level - pebble/internal/base - error.go (source / functions) Hit Total Coverage
Test: 2024-05-11 08:15Z f75ed446 - meta test only.lcov Lines: 6 21 28.6 %
Date: 2024-05-11 08:16:07 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2011 The LevelDB-Go and Pebble Authors. All rights reserved. Use
       2             : // of this source code is governed by a BSD-style license that can be found in
       3             : // the LICENSE file.
       4             : 
       5             : package base
       6             : 
       7             : import (
       8             :         "github.com/cockroachdb/errors"
       9             :         "github.com/cockroachdb/pebble/internal/invariants"
      10             : )
      11             : 
      12             : // ErrNotFound means that a get or delete call did not find the requested key.
      13             : var ErrNotFound = errors.New("pebble: not found")
      14             : 
      15             : // ErrCorruption is a marker to indicate that data in a file (WAL, MANIFEST,
      16             : // sstable) isn't in the expected format.
      17             : var ErrCorruption = errors.New("pebble: corruption")
      18             : 
      19             : // MarkCorruptionError marks given error as a corruption error.
      20           1 : func MarkCorruptionError(err error) error {
      21           1 :         if errors.Is(err, ErrCorruption) {
      22           0 :                 return err
      23           0 :         }
      24           1 :         return errors.Mark(err, ErrCorruption)
      25             : }
      26             : 
      27             : // CorruptionErrorf formats according to a format specifier and returns
      28             : // the string as an error value that is marked as a corruption error.
      29           1 : func CorruptionErrorf(format string, args ...interface{}) error {
      30           1 :         return errors.Mark(errors.Newf(format, args...), ErrCorruption)
      31           1 : }
      32             : 
      33             : // AssertionFailedf creates an assertion error and panics in invariants.Enabled
      34             : // builds. It should only be used when it indicates a bug.
      35           0 : func AssertionFailedf(format string, args ...interface{}) error {
      36           0 :         err := errors.AssertionFailedf(format, args...)
      37           0 :         if invariants.Enabled {
      38           0 :                 panic(err)
      39             :         }
      40           0 :         return err
      41             : }
      42             : 
      43             : // CatchErrorPanic runs a function and catches any panic that contains an
      44             : // error, returning that error. Used in tests, in particular to catch panics
      45             : // threw by AssertionFailedf.
      46           0 : func CatchErrorPanic(f func() error) (err error) {
      47           0 :         defer func() {
      48           0 :                 if r := recover(); r != nil {
      49           0 :                         if e, ok := r.(error); ok {
      50           0 :                                 err = e
      51           0 :                         } else {
      52           0 :                                 panic(r)
      53             :                         }
      54             :                 }
      55             :         }()
      56           0 :         return f()
      57             : }

Generated by: LCOV version 1.14