|
| 1 | +import '../objectbox.dart'; |
| 2 | + |
1 | 3 | /// Wrapper for a semantic version information.
|
2 | 4 | class Version {
|
3 | 5 | /// Major version number.
|
@@ -28,13 +30,96 @@ class ObjectBoxException implements Exception {
|
28 | 30 | String toString() => 'ObjectBoxException: $message';
|
29 | 31 | }
|
30 | 32 |
|
| 33 | +/// Thrown if a property query aggregate function (e.g. `sum()`) can not compute |
| 34 | +/// a result due to a number type overflowing. |
| 35 | +class NumericOverflowException extends ObjectBoxException { |
| 36 | + /// See [NumericOverflowException]. |
| 37 | + NumericOverflowException(String message) : super(message); |
| 38 | +} |
| 39 | + |
| 40 | +/// ObjectBox database exception with an OBX_ERROR code. |
| 41 | +class StorageException extends ObjectBoxException { |
| 42 | + /// OBX_ERROR code as defined in [objectbox.h of the C library](https://github.com/objectbox/objectbox-c/blob/main/include/objectbox.h). |
| 43 | + final int errorCode; |
| 44 | + |
| 45 | + /// Create with a message and OBX_ERROR code. |
| 46 | + StorageException(String message, this.errorCode) : super(message); |
| 47 | + |
| 48 | + @override |
| 49 | + String toString() => 'StorageException: $message (OBX_ERROR code $errorCode)'; |
| 50 | +} |
| 51 | + |
| 52 | +/// Thrown when applying a transaction (e.g. putting an object) would exceed the |
| 53 | +/// `maxDBSizeInKB` configured when calling [Store.new]. |
| 54 | +class DbFullException extends StorageException { |
| 55 | + /// See [DbFullException]. |
| 56 | + DbFullException(String message, int errorCode) : super(message, errorCode); |
| 57 | +} |
| 58 | + |
| 59 | +/// Thrown when the maximum amount of readers (read transactions) was exceeded. |
| 60 | +/// |
| 61 | +/// Verify that your code only uses a reasonable amount of threads. |
| 62 | +/// |
| 63 | +/// If a very high number of threads (>100) needs to be used, consider |
| 64 | +/// setting `maxReaders` when calling [Store.new]. |
| 65 | +class DbMaxReadersExceededException extends StorageException { |
| 66 | + /// See [DbMaxReadersExceededException]. |
| 67 | + DbMaxReadersExceededException(String message, int errorCode) |
| 68 | + : super(message, errorCode); |
| 69 | +} |
| 70 | + |
| 71 | +/// Thrown when an error occurred that requires the store to be closed. |
| 72 | +/// |
| 73 | +/// This may be an I/O error. Regular operations won't be possible. To handle |
| 74 | +/// this exit the app or try to reopen the store. |
| 75 | +class DbShutdownException extends StorageException { |
| 76 | + /// See [DbShutdownException]. |
| 77 | + DbShutdownException(String message, int errorCode) |
| 78 | + : super(message, errorCode); |
| 79 | +} |
| 80 | + |
31 | 81 | /// A unique constraint would have been violated by this database operation.
|
32 | 82 | class UniqueViolationException extends ObjectBoxException {
|
33 | 83 | /// Create a new exception.
|
34 | 84 | UniqueViolationException(String message) : super(message);
|
35 | 85 | }
|
36 | 86 |
|
37 |
| -/// Flags to enable debug options when creating a [Store]. |
| 87 | +/// Thrown when there is an error with the data schema (data model). |
| 88 | +/// |
| 89 | +/// Typically, there is a conflict between the data model defined in your code |
| 90 | +/// (using `@Entity` classes) and the data model of the existing database file. |
| 91 | +/// |
| 92 | +/// Read the [meta model docs](https://docs.objectbox.io/advanced/meta-model-ids-and-uids#resolving-meta-model-conflicts) |
| 93 | +/// on why this can happen and how to resolve such conflicts. |
| 94 | +class SchemaException extends ObjectBoxException { |
| 95 | + /// See [SchemaException]. |
| 96 | + SchemaException(String message) : super(message); |
| 97 | +} |
| 98 | + |
| 99 | +/// Errors were detected in a database file, e.g. illegal values or structural |
| 100 | +/// inconsistencies. |
| 101 | +class DbFileCorruptException extends StorageException { |
| 102 | + /// See [DbFileCorruptException]. |
| 103 | + DbFileCorruptException(String message, int errorCode) |
| 104 | + : super(message, errorCode); |
| 105 | +} |
| 106 | + |
| 107 | +/// Errors related to pages were detected in a database file, e.g. bad page refs |
| 108 | +/// outside of the file. |
| 109 | +class DbPagesCorruptException extends DbFileCorruptException { |
| 110 | + /// See [DbPagesCorruptException]. |
| 111 | + DbPagesCorruptException(String message, int errorCode) |
| 112 | + : super(message, errorCode); |
| 113 | +} |
| 114 | + |
| 115 | +/// Thrown if `Query.findUnique()` is called, but the query matches more than |
| 116 | +/// one object. |
| 117 | +class NonUniqueResultException extends ObjectBoxException { |
| 118 | + /// See [NonUniqueResultException]. |
| 119 | + NonUniqueResultException(String message) : super(message); |
| 120 | +} |
| 121 | + |
| 122 | +/// Passed as `debugFlags` when calling [Store.new] to enable debug options. |
38 | 123 | class DebugFlags {
|
39 | 124 | /// Log read transactions.
|
40 | 125 | static const int logTransactionsRead = 1;
|
|
0 commit comments