LCOV - code coverage report

Current view
top level - src/exceptions - squadron_exception.dart
Test
lcov.info
Date
2026-11-07
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines171894.4%
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 '_builtin_exceptions.dart';
7import 'worker_exception.dart';
8
9/// Base abstract class for exceptions in Squadron.
10abstract class SquadronException implements Exception {
111 SquadronException.init(this.message, [this._stackTrace]) {
121 if (_stackTrace == null) {
13 try {
142 _stackTrace = StackTrace.current;
15 } catch (_, st) {
16 // failed, take the opportunity to get the stack trace from this exception!
170 _stackTrace = st;
18 }
19 }
20 }
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].
251 static SquadronException from(Object error,
26 [StackTrace? stackTrace, int? command]) {
271 if (error is WorkerException) {
281 if (command != null) error.setCommand(command);
29 return error;
301 } else if (error is SquadronException) {
31 return error;
321 } else if (error is CanceledException) {
331 return error.toSquadronException();
341 } else if (error is TimeoutException) {
351 return error.toSquadronException();
36 } else {
372 return WorkerException(error.toString(), stackTrace, command);
38 }
39 }
40
41 final String message;
42
43 /// The exception's [StackTrace].
442 StackTrace? get stackTrace => _stackTrace;
45 StackTrace? _stackTrace;
46
471 @override
482 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.
541 static StackTrace? loadStackTrace(String? stackTrace) {
55 if (stackTrace == null) return null;
56 try {
571 return StackTrace.fromString(stackTrace);
58 } catch (_) {
59 return null;
60 }
61 }
62}
Choose Features