Skip to content

Commit 9ead369

Browse files
author
Ivan Dlugos
committed
async put - throw the new UniqueViolationException when appropriate
1 parent 0e33253 commit 9ead369

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

objectbox/lib/src/native/box.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ class _AsyncBoxHelper {
423423
if (message == null) {
424424
completer.complete(newId);
425425
} else if (message is String) {
426-
completer.completeError(ObjectBoxException(message));
426+
completer.completeError(message.startsWith('Unique constraint')
427+
? UniqueViolationException(message)
428+
: ObjectBoxException(message));
427429
} else {
428430
completer.completeError(ObjectBoxException(
429431
'Unknown message type (${message.runtimeType}: $message'));

objectbox/test/box_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ void main() {
9595
final future = box.putAsync(object);
9696
expect(
9797
future,
98-
throwsA(predicate((ObjectBoxException e) =>
98+
throwsA(predicate((UniqueViolationException e) =>
9999
e.toString().contains('Unique constraint'))));
100-
// paranoia, should already have waited on the above [expect()]
100+
101101
try {
102+
// paranoia, should already have waited on the above [expect()]
102103
await future;
103104
} catch (_) {}
105+
104106
expect(object.id, isNull); // ID must remain unassigned
105107
}
106108
});

0 commit comments

Comments
 (0)