diff --git a/CHANGELOG.md b/CHANGELOG.md index edfb04f..f5cf389 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ +## 5.3.0 +October 06, 2024 +- getter, lastErrorMessage, in AppState class in part08_app_statex.dart + ## 5.2.4 October 05, 2024 - Class, AppState, has lastFlutterError() to record and return diff --git a/lib/part08_app_statex.dart b/lib/part08_app_statex.dart index 7a9502d..bc2c4f4 100644 --- a/lib/part08_app_statex.dart +++ b/lib/part08_app_statex.dart @@ -379,7 +379,7 @@ abstract class AppStateX extends StateX try { // _onError(details); - } catch (e) { + } catch (e, stack) { // Throw in DebugMode. if (kDebugMode) { // Set the original error routine. Allows the handler to throw errors. @@ -387,7 +387,10 @@ abstract class AppStateX extends StateX // Rethrow to be handled by the original routine. rethrow; } else { - // Record error in log + // Record the error + recordException(e, stack); + + // Record error in device's log _logPackageError( e, library: 'part08_app_statex.dart', @@ -423,7 +426,7 @@ abstract class AppStateX extends StateX // The App's error handler onError(details); - // its own Error handler + // If no App Error Handler, run its own Error handler if (!_onErrorOverridden && _prevErrorFunc != null) { _prevErrorFunc!.call(details); } @@ -432,23 +435,43 @@ abstract class AppStateX extends StateX _inErrorRoutine = false; } + /// A flag indicating we're running in the error routine. + /// Set to avoid infinite loop if in errors in the error routine. + bool _inErrorRoutine = false; + + /// Supply the last Flutter Error Details if any. + FlutterErrorDetails? get lastFlutterErrorDetails => _lastFlutterErrorDetails; + /// Record and return details of the 'last' handled error + /// Not, simply retrieving the last error will 'clear' the storage. FlutterErrorDetails? lastFlutterError([FlutterErrorDetails? details]) { FlutterErrorDetails? lastErrorDetails; if (details == null) { - lastErrorDetails = _handledErrorDetails; + lastErrorDetails = _lastFlutterErrorDetails; + _lastFlutterErrorDetails = null; // Clear the storage for next time. } else { - lastErrorDetails = _handledErrorDetails = details; + lastErrorDetails = _lastFlutterErrorDetails = details; } return lastErrorDetails; } // Record the details of the last error if any - FlutterErrorDetails? _handledErrorDetails; + FlutterErrorDetails? _lastFlutterErrorDetails; - /// A flag indicating we're running in the error routine. - /// Set to avoid infinite loop if in errors in the error routine. - bool _inErrorRoutine = false; + /// Return the message of th 'last' Flutter Error if any. + String get lastFlutterErrorMessage { + String message; + final details = _lastFlutterErrorDetails; + if (details == null) { + message = ''; + } else { + message = details.exceptionAsString(); + } + if (message.contains('')) { + message = ''; + } + return message; + } /// Call the latest SateX object's error routine /// Possibly the error occurred there. diff --git a/lib/part17_record_exception_mixin.dart b/lib/part17_record_exception_mixin.dart index 1ff6e84..6b7bc1f 100644 --- a/lib/part17_record_exception_mixin.dart +++ b/lib/part17_record_exception_mixin.dart @@ -4,7 +4,7 @@ part of 'state_extended.dart'; -/// Record an exception +/// Record an exception for review by the developer /// /// dartdoc: /// {@category StateX class} @@ -35,6 +35,8 @@ mixin RecordExceptionMixin on State { Exception? _recException; /// Simply display the exception. + String get exceptionMessage => errorMsg; + @Deprecated('Use exceptionMessage instead.') String get errorMsg { String message; if (_recException == null) { diff --git a/pubspec.yaml b/pubspec.yaml index 01a163b..a2b41cf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: state_extended description: This class extends the capabilities of Flutter's State class and includes a controller. -version: 5.2.4 +version: 5.3.0 homepage: https://www.andrioussolutions.com repository: https://github.com/AndriousSolutions/state_extended