errors.go 5.0 KB

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