| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library schedule_error; | 5 library schedule_error; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| 11 import 'schedule.dart'; | 11 import 'schedule.dart'; |
| 12 import 'task.dart'; | 12 import 'task.dart'; |
| 13 import 'utils.dart'; | 13 import 'utils.dart'; |
| 14 | 14 |
| 15 /// A wrapper for errors that occur during a scheduled test. | 15 /// A wrapper for errors that occur during a scheduled test. |
| 16 class ScheduleError extends AsyncError { | 16 class ScheduleError { |
| 17 /// The wrapped error. |
| 18 final error; |
| 19 |
| 20 /// The stack trace that was attached to the error. Can be `null`. |
| 21 final stackTrace; |
| 22 |
| 17 /// The schedule during which this error occurred. | 23 /// The schedule during which this error occurred. |
| 18 final Schedule schedule; | 24 final Schedule schedule; |
| 19 | 25 |
| 20 /// The task that was running when this error occurred. This may be `null` if | 26 /// The task that was running when this error occurred. This may be `null` if |
| 21 /// there was no such task. | 27 /// there was no such task. |
| 22 final Task task; | 28 final Task task; |
| 23 | 29 |
| 24 /// The task queue that was running when this error occured. This may be | 30 /// The task queue that was running when this error occured. This may be |
| 25 /// `null` if there was no such queue. | 31 /// `null` if there was no such queue. |
| 26 final TaskQueue queue; | 32 final TaskQueue queue; |
| 27 | 33 |
| 28 /// The descriptions of out-of-band callbacks that were pending when this | 34 /// The descriptions of out-of-band callbacks that were pending when this |
| 29 /// error occurred. | 35 /// error occurred. |
| 30 final Iterable<String> pendingCallbacks; | 36 final Iterable<String> pendingCallbacks; |
| 31 | 37 |
| 32 /// The state of the schedule at the time the error was detected. | 38 /// The state of the schedule at the time the error was detected. |
| 33 final ScheduleState _stateWhenDetected; | 39 final ScheduleState _stateWhenDetected; |
| 34 | 40 |
| 35 int get hashCode => schedule.hashCode ^ task.hashCode ^ queue.hashCode ^ | 41 int get hashCode => schedule.hashCode ^ task.hashCode ^ queue.hashCode ^ |
| 36 _stateWhenDetected.hashCode ^ error.hashCode ^ stackTrace.hashCode ^ | 42 _stateWhenDetected.hashCode ^ error.hashCode ^ stackTrace.hashCode; |
| 37 cause.hashCode; | |
| 38 | 43 |
| 39 /// Creates a new [ScheduleError] wrapping [error]. The metadata in | 44 /// Creates a new [ScheduleError] wrapping [error]. The metadata in |
| 40 /// [AsyncError]s and [ScheduleError]s will be preserved. | 45 /// [ScheduleError]s will be preserved. |
| 41 factory ScheduleError.from(Schedule schedule, error, {StackTrace stackTrace, | 46 factory ScheduleError.from(Schedule schedule, error, |
| 42 AsyncError cause}) { | 47 {StackTrace stackTrace}) { |
| 43 if (error is ScheduleError) return error; | 48 if (error is ScheduleError) return error; |
| 44 | 49 |
| 45 if (error is AsyncError) { | 50 var attachedTrace = getAttachedStackTrace(error); |
| 51 if (attachedTrace != null) { |
| 46 // Overwrite the explicit stack trace, because it probably came from a | 52 // Overwrite the explicit stack trace, because it probably came from a |
| 47 // rethrow in the first place. | 53 // rethrow in the first place. |
| 48 stackTrace = error.stackTrace; | 54 stackTrace = attachedTrace; |
| 49 if (cause == null) cause = error.cause; | |
| 50 error = error.error; | |
| 51 } | 55 } |
| 52 | 56 |
| 53 if (schedule.captureStackTraces && stackTrace == null) { | 57 if (schedule.captureStackTraces && stackTrace == null) { |
| 54 stackTrace = new Trace.current(); | 58 stackTrace = new Trace.current(); |
| 55 } | 59 } |
| 56 | 60 |
| 57 return new ScheduleError(schedule, error, stackTrace, cause); | 61 return new ScheduleError(schedule, error, stackTrace); |
| 58 } | 62 } |
| 59 | 63 |
| 60 ScheduleError(Schedule schedule, error, StackTrace stackTrace, | 64 // TODO(floitsch): restore StackTrace type when it has been integrated into |
| 61 AsyncError cause) | 65 // the core libraries. |
| 62 : super.withCause(error, stackTrace, cause), | 66 ScheduleError(Schedule schedule, error, var stackTrace) |
| 67 : error = error, |
| 68 stackTrace = stackTrace, |
| 63 schedule = schedule, | 69 schedule = schedule, |
| 64 task = schedule.currentTask, | 70 task = schedule.currentTask, |
| 65 queue = schedule.currentQueue, | 71 queue = schedule.currentQueue, |
| 66 pendingCallbacks = schedule.currentQueue == null ? <String>[] | 72 pendingCallbacks = schedule.currentQueue == null ? <String>[] |
| 67 : schedule.currentQueue.pendingCallbacks.toList(), | 73 : schedule.currentQueue.pendingCallbacks.toList(), |
| 68 _stateWhenDetected = schedule.state; | 74 _stateWhenDetected = schedule.state; |
| 69 | 75 |
| 70 bool operator ==(other) => other is ScheduleError && task == other.task && | 76 bool operator ==(other) => other is ScheduleError && task == other.task && |
| 71 queue == other.queue && _stateWhenDetected == other._stateWhenDetected && | 77 queue == other.queue && _stateWhenDetected == other._stateWhenDetected && |
| 72 error == other.error && stackTrace == other.stackTrace && | 78 error == other.error && stackTrace == other.stackTrace; |
| 73 cause == other.cause; | |
| 74 | 79 |
| 75 String toString() { | 80 String toString() { |
| 76 var result = new StringBuffer(); | 81 var result = new StringBuffer(); |
| 77 | 82 |
| 78 var errorString = error.toString(); | 83 var errorString = error.toString(); |
| 79 if (errorString.contains("\n")) { | 84 if (errorString.contains("\n")) { |
| 80 result.write('ScheduleError:\n'); | 85 result.write('ScheduleError:\n'); |
| 81 result.write(prefixLines(errorString.trim())); | 86 result.write(prefixLines(errorString.trim())); |
| 82 result.write("\n\n"); | 87 result.write("\n\n"); |
| 83 } else { | 88 } else { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 107 result.write("\n\n"); | 112 result.write("\n\n"); |
| 108 result.writeln("Pending out-of-band callbacks:"); | 113 result.writeln("Pending out-of-band callbacks:"); |
| 109 for (var callback in pendingCallbacks) { | 114 for (var callback in pendingCallbacks) { |
| 110 result.writeln(prefixLines(callback, firstPrefix: "* ")); | 115 result.writeln(prefixLines(callback, firstPrefix: "* ")); |
| 111 } | 116 } |
| 112 } | 117 } |
| 113 | 118 |
| 114 return result.toString().trim(); | 119 return result.toString().trim(); |
| 115 } | 120 } |
| 116 } | 121 } |
| OLD | NEW |