Skip to content

Commit 1d2167d

Browse files
committed
Rename to UniqueViolationException
1 parent 4c8e1b7 commit 1d2167d

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 3.5.3
44

5-
- New typed exceptions: `DuplicateKeyException`, `ForeignKeyViolationException`. [#416](https://github.com/isoos/postgresql-dart/pull/416) by [hurrba](https://github.com/hurrba)
5+
- New typed exceptions: `UniqueViolationException`, `ForeignKeyViolationException`. [#416](https://github.com/isoos/postgresql-dart/pull/416) by [hurrba](https://github.com/hurrba)
66

77
## 3.5.2
88

lib/postgres.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export 'src/exceptions.dart'
2020
Severity,
2121
PgException,
2222
ServerException,
23-
DuplicateKeyException,
23+
UniqueViolationException,
2424
ForeignKeyViolationException;
2525
export 'src/pool/pool_api.dart';
2626
export 'src/replication.dart';

lib/src/exceptions.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ ServerException buildExceptionFromErrorFields(List<ErrorField> errorFields) {
191191
}
192192

193193
PgException transformServerException(ServerException ex) {
194+
// TODO: consider adding more exception from https://www.postgresql.org/docs/current/errcodes-appendix.html
194195
return switch (ex.code) {
195-
'23505' => DuplicateKeyException(ex.message, severity: ex.severity),
196+
'23505' => UniqueViolationException(ex.message, severity: ex.severity),
196197
'23503' => ForeignKeyViolationException(ex.message, severity: ex.severity),
197198
'57014' => _PgQueryCancelledException(
198199
['${ex.code}:', ex.message, ex.trace].whereType<String>().join(' '),
@@ -213,8 +214,8 @@ class _PgQueryCancelledException extends PgException
213214
});
214215
}
215216

216-
class DuplicateKeyException extends PgException {
217-
DuplicateKeyException(
217+
class UniqueViolationException extends PgException {
218+
UniqueViolationException(
218219
super.message, {
219220
required super.severity,
220221
});

test/error_handling_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void main() {
7777
try {
7878
await c.execute('INSERT INTO test (id) VALUES (1);');
7979
} catch (e) {
80-
expect(e, isA<DuplicateKeyException>());
80+
expect(e, isA<UniqueViolationException>());
8181
expect(
8282
e.toString(),
8383
contains(

test/transaction_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ void main() {
700700
// ignore
701701
}
702702
}),
703-
throwsA(isA<DuplicateKeyException>()),
703+
throwsA(isA<UniqueViolationException>()),
704704
);
705705
});
706706
});

0 commit comments

Comments
 (0)