1 | | | import 'package:meta/meta.dart'; |
2 | | |
|
3 | | | import '_well_known_exceptions.dart'; |
4 | | | import 'squadron_exception.dart'; |
5 | | |
|
6 | | | /// Exception to keep track of errors encountered in a worker. |
7 | | | class WorkerException extends SquadronException { |
8 | | | /// Creates a new [WorkerException] to capture error context. |
9 | | 10 | WorkerException(super.message, [super.stackTrace, int? command]) |
10 | | | : _command = command, |
11 | | 10 | super.init(); |
12 | | |
|
13 | | 5 | @override |
14 | | 12 | List serialize() => List.unmodifiable([ |
15 | | | $workerExceptionType, |
16 | | 7 | message, |
17 | | 12 | stackTrace?.toString(), |
18 | | 7 | _command, |
19 | | 2 | ]); |
20 | | |
|
21 | | | /// Command. |
22 | | 6 | int? get command => _command; |
23 | | | int? _command; |
24 | | | } |
25 | | |
|
26 | | | const _$type = 0; |
27 | | | const _$message = 1; |
28 | | | const _$stackTrace = 2; |
29 | | | const _$command = 3; |
30 | | |
|
31 | | | @internal |
32 | | | extension WorkerExceptionExt on WorkerException { |
33 | | 4 | void setCommand(int command) { |
34 | | 9 | _command = command; |
35 | | | } |
36 | | |
|
37 | | 11 | static WorkerException? deserialize(List data) => |
38 | | 16 | (data[_$type] == $workerExceptionType) |
39 | | 11 | ? WorkerException( |
40 | | 11 | data[_$message], |
41 | | 16 | SquadronException.loadStackTrace(data[_$stackTrace]), |
42 | | 16 | (data[_$command] as num?)?.toInt(), |
43 | | | ) |
44 | | 6 | : null; |
45 | | | } |