LCOV - code coverage report

Current view
top level - src/exceptions - exception_manager.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines233076.7%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'package:meta/meta.dart';
2
3import '_well_known_exceptions.dart';
4import 'squadron_canceled_exception.dart';
5import 'squadron_canceled_exceptions.dart';
6import 'squadron_error.dart';
7import 'squadron_exception.dart';
8import 'squadron_timeout_exception.dart';
9import 'worker_exception.dart';
10
11typedef WorkerExceptionDeserializer = WorkerException? Function(List props);
12
13@internal
14typedef SquadronExceptionDeserializer = SquadronException? Function(List props);
15
16class ExceptionManager {
1721 ExceptionManager();
18
1911 final _deserializers = <String, SquadronExceptionDeserializer>{
2011 $canceledExceptionType: SquadronCanceledExceptionExt.deserialize,
2111 $timeoutExceptionType: SquadronTimeoutExceptionExt.deserialize,
2211 $canceledExceptionsType: SquadronCanceledExceptionsExt.deserialize,
2311 $squadronErrorType: SquadronErrorExt.deserialize,
2411 $workerExceptionType: WorkerExceptionExt.deserialize,
25 };
26
27 /// Registers a deserializer for a custom [WorkerException]. If the deserializer is
28 /// already registered, registering it again will have no effect.
292 void register(
30 String exceptionTypeId, WorkerExceptionDeserializer deserializer) {
314 if ($reservedExceptionTypeIds.contains(exceptionTypeId)) {
320 throw SquadronErrorExt.create(
330 'Invalid exception type ID: $exceptionTypeId is reserved.',
34 );
35 }
366 _deserializers[exceptionTypeId] = deserializer;
37 }
38
39 /// Unregisters a deserializer that was previously registered, does nothing otherwise.
40 /// Please note that for a deregistration to have an effect, the exact same instance that
41 /// was provided to [register] must be provided to this method; avoid passing lambdas,
42 /// prefer passing static methods or top-level functions instead.
433 void unregister(String exceptionTypeId) {
444 if ($reservedExceptionTypeIds.contains(exceptionTypeId)) {
450 throw SquadronErrorExt.create(
460 'Invalid exception type ID: $exceptionTypeId is reserved.',
47 );
48 }
496 _deserializers.remove(exceptionTypeId);
501 }
51
52 /// Deserializes a [List] that was produced by [serialize].
5321 SquadronException? deserialize(List? data) {
5417 if (data == null || data.isEmpty) {
5510 return null;
56 }
570 try {
5814 final exceptionType = data[0];
5919 final deserializer = _deserializers[exceptionType];
6014 return deserializer?.call(data) ??
614 WorkerException(
624 'Failed to deserialize exception information for $exceptionType',
63 );
640 } catch (ex, st) {
650 return SquadronException.from(ex, st);
66 }
6712 }
68}
Choose Features