LCOV - code coverage report

Current view
top level - /src - worker_exception.dart
Test
lcov.info
Date
2022-04-02
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines415969.5%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'dart:async';
2
3import 'squadron_exception.dart';
4
5/// Exception to keep track of errors encountered in a worker.
6class WorkerException implements SquadronException {
7 /// Creates a new [WorkerException] to capture error context.
82 WorkerException(this.message,
9 {StackTrace? stackTrace, String? workerId, int? command})
102 : _stackTrace = stackTrace ?? StackTrace.current,
11 _workerId = workerId,
121 _command = command;
13
14 static const _$type = 0;
15 static const _$message = 1;
16 static const _$stackTrace = 2;
17 static const _$workerId = 3;
18 static const _$command = 4;
19
20 static const _$typeMarker = '\$W';
21
221 @override
231 List serialize() =>
247 [_$typeMarker, message, _stackTrace?.toString(), _workerId, _command];
25
261 static WorkerException? deserialize(List data) =>
273 (data[_$type] == _$typeMarker)
283 ? WorkerException(data[_$message],
293 stackTrace: SquadronException.loadStackTrace(data[_$stackTrace]),
302 workerId: data[_$workerId],
312 command: data[_$command])
32 : null;
33
34 /// Message.
35 final String message;
36
37 /// Stack trace associated to the original exception.
381 @override
392 StackTrace? get stackTrace => _stackTrace;
40 StackTrace? _stackTrace;
41
42 /// Worker ID.
432 String? get workerId => _workerId;
44 String? _workerId;
45
46 /// Command.
472 int? get command => _command;
48 int? _command;
49}
50
51/// Exception to keep track of task cancellation.
52class CancelledException extends WorkerException {
532 CancelledException(
54 {String? message, StackTrace? stackTrace, String? workerId, int? command})
551 : super(message ?? 'The task has been cancelled',
561 stackTrace: stackTrace, workerId: workerId, command: command);
57
58 static const _$type = 0;
59 static const _$message = 1;
60 static const _$stackTrace = 2;
61 static const _$workerId = 3;
62 static const _$command = 4;
63
64 static const _$typeMarker = '\$C';
65
661 @override
670 List serialize() =>
686 [_$typeMarker, message, _stackTrace?.toString(), _workerId, _command];
69
701 static CancelledException? deserialize(List data) =>
713 (data[_$type] == _$typeMarker)
722 ? CancelledException(
732 message: data[_$message],
743 stackTrace: SquadronException.loadStackTrace(data[_$stackTrace]),
752 workerId: data[_$workerId],
762 command: data[_$command])
77 : null;
78}
79
80/// Exception to keep track of task timeouts.
81class TaskTimeoutException extends CancelledException
82 implements TimeoutException {
83 /// Creates a new [TaskTimeoutException].
842 TaskTimeoutException(
85 {String? message,
86 StackTrace? stackTrace,
87 String? workerId,
88 int? command,
89 this.duration})
901 : super(
91 message: message ?? 'The task timed out',
92 stackTrace: stackTrace,
93 workerId: workerId,
941 command: command);
95
96 static const _$type = 0;
97 static const _$message = 1;
98 static const _$stackTrace = 2;
99 static const _$workerId = 3;
100 static const _$command = 4;
101 static const _$duration = 5;
102
103 static const _$typeMarker = '\$T';
104
1050 @override
1060 List serialize() => [
107 _$typeMarker,
1080 message,
1090 _stackTrace?.toString(),
1100 _workerId,
1110 _command,
1120 duration?.inMicroseconds
1130 ];
114
115 @override
116 final Duration? duration;
117
1181 static TaskTimeoutException? deserialize(List data) =>
1193 (data[_$type] == _$typeMarker)
1200 ? TaskTimeoutException(
1210 message: data[_$message],
1220 stackTrace: SquadronException.loadStackTrace(data[_$stackTrace]),
1230 workerId: data[_$workerId],
1240 command: data[_$command],
1250 duration: (data[_$duration] == null)
126 ? null
1270 : Duration(microseconds: data[_$duration]))
128 : null;
129}
130
131// private implementation internal to Squadron
132extension WorkerExceptionExt on WorkerException {
1332 WorkerException withWorkerId(String? workerId) {
1342 _workerId ??= workerId;
1351 return this;
1361 }
137
1382 WorkerException withCommand(int? command) {
1392 _command ??= command;
1401 return this;
1411 }
142
1430 WorkerException withStackTrace(StackTrace? stackTrace) {
1440 _stackTrace ??= stackTrace;
145 return this;
146 }
147}
Choose Features