diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a23eb8..ea74c9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 3.5.4 + +**Warning**: This version fixes the inconsistency of `3.5.3` by: +- `UniqueViolationException` and `ForeignKeyViolationException` extends `ServerException` instead of `PgException`, and +- they no longer have public constructor (please open an issue if this is something you'd rely on). +- The exception from cancelling the statement is also extends `ServerException` instead of `PgException`. + ## 3.5.3 - New typed exceptions: `UniqueViolationException`, `ForeignKeyViolationException`. [#416](https://github.com/isoos/postgresql-dart/pull/416) by [hurrba](https://github.com/hurrba) diff --git a/lib/src/exceptions.dart b/lib/src/exceptions.dart index 94ef896..8cfcdd0 100644 --- a/lib/src/exceptions.dart +++ b/lib/src/exceptions.dart @@ -138,6 +138,27 @@ class ServerException extends PgException { this.routineName, }); + ServerException._from(ServerException original) + : this._( + original.message, + severity: original.severity, + position: original.position, + internalPosition: original.internalPosition, + lineNumber: original.lineNumber, + code: original.code, + detail: original.detail, + hint: original.hint, + internalQuery: original.internalQuery, + trace: original.trace, + schemaName: original.schemaName, + tableName: original.tableName, + columnName: original.columnName, + dataTypeName: original.dataTypeName, + constraintName: original.constraintName, + fileName: original.fileName, + routineName: original.routineName, + ); + @override String toString() { final buff = StringBuffer('$severity $code: $message'); @@ -193,37 +214,28 @@ ServerException buildExceptionFromErrorFields(List errorFields) { PgException transformServerException(ServerException ex) { // TODO: consider adding more exception from https://www.postgresql.org/docs/current/errcodes-appendix.html return switch (ex.code) { - '23505' => UniqueViolationException(ex.message, severity: ex.severity), - '23503' => ForeignKeyViolationException(ex.message, severity: ex.severity), - '57014' => _PgQueryCancelledException( - ['${ex.code}:', ex.message, ex.trace].whereType().join(' '), - severity: ex.severity, + '23505' => UniqueViolationException._(ex), + '23503' => ForeignKeyViolationException._(ex), + '57014' => _PgQueryCancelledException._( + ex, + // [ex.message, ex.trace].whereType().join(' '), ), _ => ex, }; } -class _PgQueryCancelledException extends PgException +class _PgQueryCancelledException extends ServerException implements TimeoutException { @override late final duration = null; - _PgQueryCancelledException( - super.message, { - required super.severity, - }); + _PgQueryCancelledException._(super.original) : super._from(); } -class UniqueViolationException extends PgException { - UniqueViolationException( - super.message, { - required super.severity, - }); +class UniqueViolationException extends ServerException { + UniqueViolationException._(super.original) : super._from(); } -class ForeignKeyViolationException extends PgException { - ForeignKeyViolationException( - super.message, { - required super.severity, - }); +class ForeignKeyViolationException extends ServerException { + ForeignKeyViolationException._(super.original) : super._from(); } diff --git a/pubspec.yaml b/pubspec.yaml index 61986f9..b24e6df 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: postgres -description: PostgreSQL database driver. Supports statement reuse and binary protocol and connection pooling. -version: 3.5.3 +description: PostgreSQL database driver. Supports binary protocol, connection pooling and statement reuse. +version: 3.5.4 homepage: https://github.com/isoos/postgresql-dart topics: - sql