LCOV - code coverage report

Current view
top level - src/exceptions - exception_manager.dart
Test
lcov.info
Date
2025-03-26
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines141973.7%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import '_builtin_exceptions.dart';
2import 'squadron_error.dart';
3import 'squadron_exception.dart';
4import 'worker_exception.dart';
5
6typedef WorkerExceptionDeserializer = WorkerException? Function(List props);
7
8class ExceptionManager {
911 ExceptionManager();
10
11 final _deserializers = Map.from(builtinExceptions);
12
13 /// Registers a deserializer for a custom [WorkerException]. If the deserializer is
14 /// already registered, registering it again will have no effect.
152 void register(
16 String exceptionTypeId, WorkerExceptionDeserializer deserializer) {
174 if (builtinExceptions.containsKey(exceptionTypeId)) {
180 throw SquadronErrorImpl.create(
190 'Invalid exception type ID: $exceptionTypeId is reserved.',
20 );
21 }
224 _deserializers[exceptionTypeId] = deserializer;
23 }
24
25 /// Unregisters a deserializer that was previously registered, does nothing otherwise.
26 /// Please note that for a deregistration to have an effect, the exact same instance that
27 /// was provided to [register] must be provided to this method; avoid passing lambdas,
28 /// prefer passing static methods or top-level functions instead.
292 void unregister(String exceptionTypeId) {
304 if (builtinExceptions.containsKey(exceptionTypeId)) {
310 throw SquadronErrorImpl.create(
320 'Invalid exception type ID: $exceptionTypeId is reserved.',
33 );
34 }
354 _deserializers.remove(exceptionTypeId);
36 }
37
38 /// Deserializes a [List] that was produced by [serialize].
3910 SquadronException? deserialize(List? data) {
405 if (data == null || data.isEmpty) {
41 return null;
42 }
43 try {
445 final exceptionType = data[0];
4510 final deserializer = _deserializers[exceptionType];
465 return deserializer?.call(data) ??
472 WorkerException(
482 'Failed to deserialize exception information for $exceptionType',
49 );
50 } catch (ex, st) {
510 return SquadronException.from(ex, st);
52 }
53 }
54}
Choose Features