1 | | | import 'dart:convert'; |
2 | | |
|
3 | | | import 'squadron_exception.dart'; |
4 | | |
|
5 | | | /// Squadron Error |
6 | | | class SquadronError extends Error implements SquadronException { |
7 | | 2 | SquadronError._(this.message) { |
8 | | 3 | _localStackTrace = super.stackTrace; |
9 | | 1 | } |
10 | | |
|
11 | | | /// Message (or string representation of the exception). |
12 | | | final String message; |
13 | | |
|
14 | | | static const _$type = 0; |
15 | | | static const _$message = 1; |
16 | | | static const _$stackTrace = 2; |
17 | | |
|
18 | | | static const _$typeMarker = '\$'; |
19 | | |
|
20 | | 1 | @override |
21 | | 4 | List serialize() => [_$typeMarker, message, stackTrace?.toString()]; |
22 | | |
|
23 | | 1 | late StackTrace? _localStackTrace; |
24 | | | StackTrace? _remoteStackTrace; |
25 | | |
|
26 | | 1 | @override |
27 | | 3 | StackTrace? get stackTrace => _remoteStackTrace ?? _localStackTrace; |
28 | | |
|
29 | | 1 | static SquadronError? deserialize(List data) { |
30 | | | SquadronError? error; |
31 | | 3 | if (data[_$type] == _$typeMarker) { |
32 | | 3 | error = SquadronError._(data[_$message]); |
33 | | 2 | error._remoteStackTrace = |
34 | | 3 | SquadronException.loadStackTrace(data[_$stackTrace]); |
35 | | | } |
36 | | 1 | return error; |
37 | | | } |
38 | | |
|
39 | | 1 | @override |
40 | | 3 | String toString() => jsonEncode(serialize()); |
41 | | | } |
42 | | |
|
43 | | 3 | SquadronError newSquadronError(String message) => SquadronError._(message); |