| 1 |  |  | import 'package:meta/meta.dart'; | 
                
                
                    | 2 |  |  |  | 
                
                
                    | 3 |  |  | import '_builtin_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 |  | 7 |   WorkerException(super.message, [super.stackTrace, int? command]) | 
                
                
                    | 10 |  |  |       : _command = command, | 
                
                
                    | 11 |  | 7 |         super.init(); | 
                
                
                    | 12 |  |  |  | 
                
                
                    | 13 |  | 5 |   @override | 
                
                
                    | 14 |  | 10 |   List serialize() => List.unmodifiable([ | 
                
                
                    | 15 |  |  |         $workerExceptionType, | 
                
                
                    | 16 |  | 5 |         message, | 
                
                
                    | 17 |  | 10 |         stackTrace?.toString(), | 
                
                
                    | 18 |  | 5 |         _command, | 
                
                
                    | 19 |  |  |       ]); | 
                
                
                    | 20 |  |  |  | 
                
                
                    | 21 |  |  |   /// Command. | 
                
                
                    | 22 |  | 4 |   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 WorkerExceptionImpl on WorkerException { | 
                
                
                    | 33 |  | 4 |   void setCommand(int command) { | 
                
                
                    | 34 |  | 4 |     _command = command; | 
                
                
                    | 35 |  |  |   } | 
                
                
                    | 36 |  |  |  | 
                
                
                    | 37 |  | 5 |   static WorkerException? deserialize(List data) => | 
                
                
                    | 38 |  | 10 |       (data[_$type] == $workerExceptionType) | 
                
                
                    | 39 |  | 5 |           ? WorkerException( | 
                
                
                    | 40 |  | 5 |               data[_$message], | 
                
                
                    | 41 |  | 10 |               SquadronException.loadStackTrace(data[_$stackTrace]), | 
                
                
                    | 42 |  | 10 |               (data[_$command] as num?)?.toInt(), | 
                
                
                    | 43 |  |  |             ) | 
                
                
                    | 44 |  |  |           : null; | 
                
                
                    | 45 |  |  | } |