LCOV - code coverage report

Current view
top level - src/exceptions - squadron_exception.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines212487.5%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'dart:async';
2import 'dart:convert';
3
4import 'package:cancelation_token/cancelation_token.dart';
5
6import '_well_known_exceptions.dart';
7import 'worker_exception.dart';
8
9/// Base abstract class for exceptions in Squadron.
10abstract class SquadronException implements Exception {
1120 SquadronException.init(this.message, [this._stackTrace]) {
1220 if (_stackTrace == null) {
13 try {
1426 _stackTrace = StackTrace.current;
150 } catch (_, st) {
16 // failed, take the opportunity to get the stack trace from this exception!
170 _stackTrace = st;
18 }
19 }
2010 }
21
22 /// This method returns [error] if it is a [SquadronException] (enriching it
23 /// with [command] if it is a [WorkerException]). Otherwise, it returns a new
24 /// [WorkerException] wrapping [error] and [stackTrace].
2516 static SquadronException from(Object error,
26 [StackTrace? stackTrace, int? command]) {
2716 if (error is WorkerException) {
289 if (command != null) error.setCommand(command);
295 return error;
309 } else if (error is SquadronException) {
315 return error;
325 } else if (error is CanceledException) {
332 return error.toSquadronException();
345 } else if (error is TimeoutException) {
352 return error.toSquadronException();
36 } else {
379 return WorkerException(error.toString(), stackTrace, command);
38 }
399 }
40
41 final String message;
42
43 /// The exception's [StackTrace].
4416 StackTrace? get stackTrace => _stackTrace;
450 StackTrace? _stackTrace;
46
472 @override
485 String toString() => jsonEncode(serialize());
49
50 /// Serializes the exception, i.e. returns a list of items that can cross thread boundaries.
51 List serialize();
52
53 /// Deserializes a [stackTrace] if any. Returns null if no [StackTrace] is provided.
549 static StackTrace? loadStackTrace(String? stackTrace) =>
556 (stackTrace == null) ? null : StackTrace.fromString(stackTrace);
56}
Choose Features