errors.go raw

   1  /*
   2   * SPDX-FileCopyrightText: © Hypermode Inc. <hello@hypermode.com>
   3   * SPDX-License-Identifier: Apache-2.0
   4   */
   5  
   6  package badger
   7  
   8  import (
   9  	stderrors "errors"
  10  	"math"
  11  )
  12  
  13  const (
  14  	// ValueThresholdLimit is the maximum permissible value of opt.ValueThreshold.
  15  	ValueThresholdLimit = math.MaxUint16 - 16 + 1
  16  )
  17  
  18  var (
  19  	// ErrValueLogSize is returned when opt.ValueLogFileSize option is not within the valid
  20  	// range.
  21  	ErrValueLogSize = stderrors.New("Invalid ValueLogFileSize, must be in range [1MB, 2GB)")
  22  
  23  	// ErrKeyNotFound is returned when key isn't found on a txn.Get.
  24  	ErrKeyNotFound = stderrors.New("Key not found")
  25  
  26  	// ErrTxnTooBig is returned if too many writes are fit into a single transaction.
  27  	ErrTxnTooBig = stderrors.New("Txn is too big to fit into one request")
  28  
  29  	// ErrConflict is returned when a transaction conflicts with another transaction. This can
  30  	// happen if the read rows had been updated concurrently by another transaction.
  31  	ErrConflict = stderrors.New("Transaction Conflict. Please retry")
  32  
  33  	// ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.
  34  	ErrReadOnlyTxn = stderrors.New("No sets or deletes are allowed in a read-only transaction")
  35  
  36  	// ErrDiscardedTxn is returned if a previously discarded transaction is re-used.
  37  	ErrDiscardedTxn = stderrors.New("This transaction has been discarded. Create a new one")
  38  
  39  	// ErrEmptyKey is returned if an empty key is passed on an update function.
  40  	ErrEmptyKey = stderrors.New("Key cannot be empty")
  41  
  42  	// ErrInvalidKey is returned if the key has a special !badger! prefix,
  43  	// reserved for internal usage.
  44  	ErrInvalidKey = stderrors.New("Key is using a reserved !badger! prefix")
  45  
  46  	// ErrBannedKey is returned if the read/write key belongs to any banned namespace.
  47  	ErrBannedKey = stderrors.New("Key is using the banned prefix")
  48  
  49  	// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.
  50  	// In such a case, GC can't be run.
  51  	ErrThresholdZero = stderrors.New(
  52  		"Value log GC can't run because threshold is set to zero")
  53  
  54  	// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.
  55  	ErrNoRewrite = stderrors.New(
  56  		"Value log GC attempt didn't result in any cleanup")
  57  
  58  	// ErrRejected is returned if a value log GC is called either while another GC is running, or
  59  	// after DB::Close has been called.
  60  	ErrRejected = stderrors.New("Value log GC request rejected")
  61  
  62  	// ErrInvalidRequest is returned if the user request is invalid.
  63  	ErrInvalidRequest = stderrors.New("Invalid request")
  64  
  65  	// ErrManagedTxn is returned if the user tries to use an API which isn't
  66  	// allowed due to external management of transactions, when using ManagedDB.
  67  	ErrManagedTxn = stderrors.New(
  68  		"Invalid API request. Not allowed to perform this action using ManagedDB")
  69  
  70  	// ErrNamespaceMode is returned if the user tries to use an API which is allowed only when
  71  	// NamespaceOffset is non-negative.
  72  	ErrNamespaceMode = stderrors.New(
  73  		"Invalid API request. Not allowed to perform this action when NamespaceMode is not set.")
  74  
  75  	// ErrInvalidDump if a data dump made previously cannot be loaded into the database.
  76  	ErrInvalidDump = stderrors.New("Data dump cannot be read")
  77  
  78  	// ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.
  79  	ErrZeroBandwidth = stderrors.New("Bandwidth must be greater than zero")
  80  
  81  	// ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows
  82  	ErrWindowsNotSupported = stderrors.New("Read-only mode is not supported on Windows")
  83  
  84  	// ErrPlan9NotSupported is returned when opt.ReadOnly is used on Plan 9
  85  	ErrPlan9NotSupported = stderrors.New("Read-only mode is not supported on Plan 9")
  86  
  87  	// ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of
  88  	// corrupt data to allow Badger to run properly.
  89  	ErrTruncateNeeded = stderrors.New(
  90  		"Log truncate required to run DB. This might result in data loss")
  91  
  92  	// ErrBlockedWrites is returned if the user called DropAll. During the process of dropping all
  93  	// data from Badger, we stop accepting new writes, by returning this error.
  94  	ErrBlockedWrites = stderrors.New("Writes are blocked, possibly due to DropAll or Close")
  95  
  96  	// ErrNilCallback is returned when subscriber's callback is nil.
  97  	ErrNilCallback = stderrors.New("Callback cannot be nil")
  98  
  99  	// ErrEncryptionKeyMismatch is returned when the storage key is not
 100  	// matched with the key previously given.
 101  	ErrEncryptionKeyMismatch = stderrors.New("Encryption key mismatch")
 102  
 103  	// ErrInvalidDataKeyID is returned if the datakey id is invalid.
 104  	ErrInvalidDataKeyID = stderrors.New("Invalid datakey id")
 105  
 106  	// ErrInvalidEncryptionKey is returned if length of encryption keys is invalid.
 107  	ErrInvalidEncryptionKey = stderrors.New("Encryption key's length should be" +
 108  		"either 16, 24, or 32 bytes")
 109  	// ErrGCInMemoryMode is returned when db.RunValueLogGC is called in in-memory mode.
 110  	ErrGCInMemoryMode = stderrors.New("Cannot run value log GC when DB is opened in InMemory mode")
 111  
 112  	// ErrDBClosed is returned when a get operation is performed after closing the DB.
 113  	ErrDBClosed = stderrors.New("DB Closed")
 114  )
 115