LCOV - code coverage report

Current view
top level - src/exceptions - squadron_exception.dart
Test
lcov.info
Date
2025-03-26
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 {
1112 SquadronException.init(this.message, [this._stackTrace]) {
1212 if (_stackTrace == null) {
13 try {
1424 _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].
258 static SquadronException from(Object error,
26 [StackTrace? stackTrace, int? command]) {
278 if (error is WorkerException) {
284 if (command != null) error.setCommand(command);
29 return error;
307 } else if (error is SquadronException) {
31 return error;
324 } else if (error is CanceledException) {
332 return error.toSquadronException();
344 } else if (error is TimeoutException) {
352 return error.toSquadronException();
36 } else {
378 return WorkerException(error.toString(), stackTrace, command);
38 }
39 }
40
41 final String message;
42
43 /// The exception's [StackTrace].
4412 StackTrace? get stackTrace => _stackTrace;
45 StackTrace? _stackTrace;
46
472 @override
484 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.
5410 static StackTrace? loadStackTrace(String? stackTrace) {
55 if (stackTrace == null) return null;
56 try {
576 return StackTrace.fromString(stackTrace);
58 } catch (_) {
59 return null;
60 }
61 }
62}
Choose Features