Chromium Code Reviews| 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 'schedule.dart'; | 9 import 'schedule.dart'; |
| 10 import 'task.dart'; | 10 import 'task.dart'; |
| 11 import 'utils.dart'; | 11 import 'utils.dart'; |
| 12 | 12 |
| 13 /// A wrapper for errors that occur during a scheduled test. | 13 /// A wrapper for errors that occur during a scheduled test. |
| 14 class ScheduleError extends AsyncError { | 14 class ScheduleError extends AsyncError { |
| 15 /// The schedule during which this error occurred. | 15 /// The schedule during which this error occurred. |
| 16 final Schedule schedule; | 16 final Schedule schedule; |
| 17 | 17 |
| 18 /// The task that was running when this error occurred. This may be `null` if | 18 /// The task that was running when this error occurred. This may be `null` if |
| 19 /// there was no such task. | 19 /// there was no such task. |
| 20 final Task task; | 20 final Task task; |
| 21 | 21 |
| 22 /// The task queue that was running when this error occured. This may be | 22 /// The task queue that was running when this error occured. This may be |
| 23 /// `null` if there was no such queue. | 23 /// `null` if there was no such queue. |
| 24 final TaskQueue queue; | 24 final TaskQueue queue; |
| 25 | 25 |
| 26 /// The descriptions of out-of-band callbacks that were pending when this | |
| 27 /// error occurred. | |
| 28 final Collection<String> pendingCallbacks; | |
| 29 | |
| 26 /// The state of the schedule at the time the error was detected. | 30 /// The state of the schedule at the time the error was detected. |
| 27 final ScheduleState _stateWhenDetected; | 31 final ScheduleState _stateWhenDetected; |
| 28 | 32 |
| 29 int get hashCode => schedule.hashCode ^ task.hashCode ^ queue.hashCode ^ | 33 int get hashCode => schedule.hashCode ^ task.hashCode ^ queue.hashCode ^ |
| 30 _stateWhenDetected.hashCode ^ error.hashCode ^ stackTrace.hashCode ^ | 34 _stateWhenDetected.hashCode ^ error.hashCode ^ stackTrace.hashCode ^ |
| 31 cause.hashCode; | 35 cause.hashCode; |
| 32 | 36 |
| 33 /// Creates a new [ScheduleError] wrapping [error]. The metadata in | 37 /// Creates a new [ScheduleError] wrapping [error]. The metadata in |
| 34 /// [AsyncError]s and [ScheduleError]s will be preserved. | 38 /// [AsyncError]s and [ScheduleError]s will be preserved. |
| 35 factory ScheduleError.from(Schedule schedule, error, {stackTrace, | 39 factory ScheduleError.from(Schedule schedule, error, {stackTrace, |
| 36 AsyncError cause}) { | 40 AsyncError cause}) { |
| 37 if (error is ScheduleError) return error; | 41 if (error is ScheduleError) return error; |
| 38 | 42 |
| 39 if (error is AsyncError) { | 43 if (error is AsyncError) { |
| 40 // Overwrite the explicit stack trace, because it probably came from a | 44 // Overwrite the explicit stack trace, because it probably came from a |
| 41 // rethrow in the first place. | 45 // rethrow in the first place. |
| 42 stackTrace = error.stackTrace; | 46 stackTrace = error.stackTrace; |
| 43 if (cause == null) cause = error.cause; | 47 if (cause == null) cause = error.cause; |
| 44 error = error.error; | 48 error = error.error; |
| 45 } | 49 } |
| 46 | 50 |
| 47 return new ScheduleError(schedule, error, stackTrace, cause); | 51 return new ScheduleError(schedule, error, stackTrace, cause); |
| 48 } | 52 } |
| 49 | 53 |
| 50 ScheduleError(Schedule schedule, error, stackTrace, AsyncError cause) | 54 ScheduleError(Schedule schedule, error, stackTrace, AsyncError cause) |
| 51 : super.withCause(error, stackTrace, cause), | 55 : super.withCause(error, stackTrace, cause), |
| 52 this.schedule = schedule, | 56 this.schedule = schedule, |
|
Bob Nystrom
2013/03/12 20:08:51
Are the "this."s needed here?
nweiz
2013/03/12 20:56:51
No, removed.
| |
| 53 this.task = schedule.currentTask, | 57 this.task = schedule.currentTask, |
| 54 this.queue = schedule.currentQueue, | 58 this.queue = schedule.currentQueue, |
| 59 this.pendingCallbacks = schedule.currentQueue == null ? <String>[] | |
| 60 : new List<String>.from(schedule.currentQueue.pendingCallbacks), | |
|
Bob Nystrom
2013/03/12 20:08:51
schedule.currentQueue.pendingCallbacks.toList()
nweiz
2013/03/12 20:56:51
Done.
| |
| 55 this._stateWhenDetected = schedule.state; | 61 this._stateWhenDetected = schedule.state; |
| 56 | 62 |
| 57 bool operator ==(other) => other is ScheduleError && task == other.task && | 63 bool operator ==(other) => other is ScheduleError && task == other.task && |
| 58 queue == other.queue && _stateWhenDetected == other._stateWhenDetected && | 64 queue == other.queue && _stateWhenDetected == other._stateWhenDetected && |
| 59 error == other.error && stackTrace == other.stackTrace && | 65 error == other.error && stackTrace == other.stackTrace && |
| 60 cause == other.cause; | 66 cause == other.cause; |
| 61 | 67 |
| 62 String toString() { | 68 String toString() { |
| 63 var result = new StringBuffer(); | 69 var result = new StringBuffer(); |
| 64 | 70 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 81 } else if (_stateWhenDetected == ScheduleState.DONE) { | 87 } else if (_stateWhenDetected == ScheduleState.DONE) { |
| 82 result.write('Error detected after all tasks in the schedule had ' | 88 result.write('Error detected after all tasks in the schedule had ' |
| 83 'finished.'); | 89 'finished.'); |
| 84 } else if (_stateWhenDetected == ScheduleState.RUNNING) { | 90 } else if (_stateWhenDetected == ScheduleState.RUNNING) { |
| 85 result.write('Error detected when waiting for out-of-band callbacks in ' | 91 result.write('Error detected when waiting for out-of-band callbacks in ' |
| 86 'queue "$queue".'); | 92 'queue "$queue".'); |
| 87 } else { // _stateWhenDetected == ScheduleState.SET_UP | 93 } else { // _stateWhenDetected == ScheduleState.SET_UP |
| 88 result.write('Error detected before the schedule started running.'); | 94 result.write('Error detected before the schedule started running.'); |
| 89 } | 95 } |
| 90 | 96 |
| 91 return result.toString(); | 97 if (!pendingCallbacks.isEmpty) { |
| 98 result.write("\n\n"); | |
| 99 result.writeln("Pending out-of-band callbacks:"); | |
| 100 for (var callback in pendingCallbacks) { | |
| 101 result.writeln("* $callback"); | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 return result.toString().trim(); | |
| 92 } | 106 } |
| 93 } | 107 } |
| OLD | NEW |