Skip to content

Commit 2d2f1d3

Browse files
Throw DbFullException for error code OBX_ERROR_DB_FULL (#31)
1 parent 6e9c606 commit 2d2f1d3

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

objectbox/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* Generator not longer warns that it can not find the package source root if the output directory is
1212
the package root directory.
1313
* Add `StorageException` which is a `ObjectBoxException` with an `errorCode` (a `OBX_ERROR` code).
14+
* Throw `DbFullException` instead of `ObjectBoxException` with message `10101 Could not put` (error
15+
code `OBX_ERROR_DB_FULL`).
1416

1517
## 1.6.2 (2022-08-24)
1618

objectbox/lib/src/common.dart

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import '../objectbox.dart';
2+
13
/// Wrapper for a semantic version information.
24
class Version {
35
/// Major version number.
@@ -40,6 +42,13 @@ class StorageException extends ObjectBoxException {
4042
String toString() => 'StorageException: $message (OBX_ERROR code $errorCode)';
4143
}
4244

45+
/// Thrown when applying a transaction (e.g. putting an object) would exceed the
46+
/// `maxDBSizeInKB` configured when calling [Store.new].
47+
class DbFullException extends StorageException {
48+
/// See [DbFullException].
49+
DbFullException(String message, int errorCode) : super(message, errorCode);
50+
}
51+
4352
/// A unique constraint would have been violated by this database operation.
4453
class UniqueViolationException extends ObjectBoxException {
4554
/// Create a new exception.

objectbox/lib/src/native/bindings/helpers.dart

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class ObjectBoxNativeError {
7878
throw RangeError(messageWithErrorCode);
7979
case OBX_ERROR_UNIQUE_VIOLATED:
8080
throw UniqueViolationException(messageWithContext);
81+
case OBX_ERROR_DB_FULL:
82+
throw DbFullException(messageWithContext, code);
8183
default:
8284
if (code == 0) {
8385
throw ObjectBoxException(messageWithContext);

objectbox/lib/src/native/store.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,16 @@ class Store {
9898
/// ## Maximum database size
9999
///
100100
/// [maxDBSizeInKB] sets the maximum size the database file can grow to.
101-
/// By default this is 1 GB, which should be sufficient for most applications.
102-
/// The store will throw when trying to insert more data if the maximum size
103-
/// is reached.
101+
/// When applying a transaction (e.g. putting an object) would exceed it a
102+
/// [DbFullException] is thrown.
104103
///
104+
/// By default, this is 1 GB, which should be sufficient for most applications.
105105
/// In general, a maximum size prevents the database from growing indefinitely
106106
/// when something goes wrong (for example data is put in an infinite loop).
107107
///
108+
/// This value can be changed, so increased or also decreased, each time when
109+
/// opening a store.
110+
///
108111
/// ## File mode
109112
///
110113
/// Specify [unix-style file permissions](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation)

objectbox/test/store_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void main() {
248248
expect(
249249
() => box.put(testEntity2),
250250
throwsA(predicate((e) =>
251-
e is StorageException &&
251+
e is DbFullException &&
252252
e.errorCode == OBX_ERROR_DB_FULL &&
253253
e.message == 'object put failed: Could not put')));
254254

0 commit comments

Comments
 (0)