diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aebe04..070bcd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 1.9.26 + +- `Initializable` mixin: + - `ensureInitialized`: added `onError` handler to `then` call to route errors to `_onInitializationError`. + - `executeInitializedCallback`: + - Added `onError` handler to `then` call on async initialization result to throw `InitializationError` with stack trace. + - `_FutureExtension`: + - `toCompleter`: added `onError` handler to `then` to complete completer with error and stack trace if not completed. + ## 1.9.25 - `TableFieldReference`: diff --git a/lib/src/bones_api_base.dart b/lib/src/bones_api_base.dart index 4a67dac..89d361d 100644 --- a/lib/src/bones_api_base.dart +++ b/lib/src/bones_api_base.dart @@ -48,7 +48,7 @@ typedef APILogger = /// Bones API Library class. class BonesAPI { // ignore: constant_identifier_names - static const String VERSION = '1.9.25'; + static const String VERSION = '1.9.26'; static bool _boot = false; diff --git a/lib/src/bones_api_initializable.dart b/lib/src/bones_api_initializable.dart index 6dea8c4..b6dd44f 100644 --- a/lib/src/bones_api_initializable.dart +++ b/lib/src/bones_api_initializable.dart @@ -1009,7 +1009,7 @@ mixin Initializable { } return _finalizeInitializationWithDeps2(depsResults, result); - }); + }, onError: (e, s) => _onInitializationError(e, s)); } else { return _finalizeInitializationWithDeps2(depsResults, result); } @@ -1107,13 +1107,21 @@ mixin Initializable { var ret = ensureInitialized(parent: parent); if (ret is Future) { - return ret.then((result) { - if (!result.ok) { - _forceLogFlushMessages(); + return ret.then( + (result) { + if (!result.ok) { + _forceLogFlushMessages(); + throw InitializationError( + this, + "Error initializing (async): $this", + ); + } + return callback(); + }, + onError: (e, s) { throw InitializationError(this, "Error initializing (async): $this"); - } - return callback(); - }); + }, + ); } else { if (!ret.ok) { _forceLogFlushMessages(); @@ -1284,11 +1292,18 @@ extension _FutureExtension on Future { Completer toCompleter() { var completer = Completer(); // ignore: discarded_futures - then((val) { - if (!completer.isCompleted) { - completer.complete(val); - } - }); + then( + (val) { + if (!completer.isCompleted) { + completer.complete(val); + } + }, + onError: (e, s) { + if (!completer.isCompleted) { + completer.completeError(e, s); + } + }, + ); return completer; } } diff --git a/pubspec.yaml b/pubspec.yaml index 95b738f..1f0a323 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bones_api description: Bones_API - A powerful API backend framework for Dart. It comes with a built-in HTTP Server, route handler, entity handler, SQL translator, and DB adapters. -version: 1.9.25 +version: 1.9.26 homepage: https://github.com/Colossus-Services/bones_api environment: