| 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 state of the schedule at the time the error was detected. | 26 /// The state of the schedule at the time the error was detected. |
| 27 final ScheduleState _stateWhenDetected; | 27 final ScheduleState _stateWhenDetected; |
| 28 | 28 |
| 29 int get hashCode => schedule.hashCode ^ task.hashCode ^ queue.hashCode ^ |
| 30 _stateWhenDetected.hashCode ^ error.hashCode ^ stackTrace.hashCode ^ |
| 31 cause.hashCode; |
| 32 |
| 29 /// Creates a new [ScheduleError] wrapping [error]. The metadata in | 33 /// Creates a new [ScheduleError] wrapping [error]. The metadata in |
| 30 /// [AsyncError]s and [ScheduleError]s will be preserved. | 34 /// [AsyncError]s and [ScheduleError]s will be preserved. |
| 31 factory ScheduleError.from(Schedule schedule, error, {stackTrace, | 35 factory ScheduleError.from(Schedule schedule, error, {stackTrace, |
| 32 AsyncError cause}) { | 36 AsyncError cause}) { |
| 33 if (error is ScheduleError) { | 37 if (error is ScheduleError) return error; |
| 34 if (schedule == null) schedule = error.schedule; | |
| 35 } | |
| 36 | 38 |
| 37 if (error is AsyncError) { | 39 if (error is AsyncError) { |
| 38 // Overwrite the explicit stack trace, because it probably came from a | 40 // Overwrite the explicit stack trace, because it probably came from a |
| 39 // rethrow in the first place. | 41 // rethrow in the first place. |
| 40 stackTrace = error.stackTrace; | 42 stackTrace = error.stackTrace; |
| 41 if (cause == null) cause = error.cause; | 43 if (cause == null) cause = error.cause; |
| 42 error = error.error; | 44 error = error.error; |
| 43 } | 45 } |
| 44 | 46 |
| 45 return new ScheduleError(schedule, error, stackTrace, cause); | 47 return new ScheduleError(schedule, error, stackTrace, cause); |
| 46 } | 48 } |
| 47 | 49 |
| 48 ScheduleError(Schedule schedule, error, stackTrace, AsyncError cause) | 50 ScheduleError(Schedule schedule, error, stackTrace, AsyncError cause) |
| 49 : super.withCause(error, stackTrace, cause), | 51 : super.withCause(error, stackTrace, cause), |
| 50 this.schedule = schedule, | 52 this.schedule = schedule, |
| 51 this.task = schedule.currentTask, | 53 this.task = schedule.currentTask, |
| 52 this.queue = schedule.currentQueue, | 54 this.queue = schedule.currentQueue, |
| 53 this._stateWhenDetected = schedule.state; | 55 this._stateWhenDetected = schedule.state; |
| 54 | 56 |
| 57 bool operator ==(other) => other is ScheduleError && task == other.task && |
| 58 queue == other.queue && _stateWhenDetected == other._stateWhenDetected && |
| 59 error == other.error && stackTrace == other.stackTrace && |
| 60 cause == other.cause; |
| 61 |
| 55 String toString() { | 62 String toString() { |
| 56 var result = new StringBuffer(); | 63 var result = new StringBuffer(); |
| 57 | 64 |
| 58 var errorString = error.toString(); | 65 var errorString = error.toString(); |
| 59 if (errorString.contains("\n")) { | 66 if (errorString.contains("\n")) { |
| 60 result.add('ScheduleError:\n'); | 67 result.add('ScheduleError:\n'); |
| 61 result.add(prefixLines(errorString.trim())); | 68 result.add(prefixLines(errorString.trim())); |
| 62 result.add("\n\n"); | 69 result.add("\n\n"); |
| 63 } else { | 70 } else { |
| 64 result.add('ScheduleError: "$errorString"\n'); | 71 result.add('ScheduleError: "$errorString"\n'); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 } else if (_stateWhenDetected == ScheduleState.RUNNING) { | 84 } else if (_stateWhenDetected == ScheduleState.RUNNING) { |
| 78 result.add('Error detected when waiting for out-of-band callbacks in ' | 85 result.add('Error detected when waiting for out-of-band callbacks in ' |
| 79 'queue "$queue".'); | 86 'queue "$queue".'); |
| 80 } else { // _stateWhenDetected == ScheduleState.SET_UP | 87 } else { // _stateWhenDetected == ScheduleState.SET_UP |
| 81 result.add('Error detected before the schedule started running.'); | 88 result.add('Error detected before the schedule started running.'); |
| 82 } | 89 } |
| 83 | 90 |
| 84 return result.toString(); | 91 return result.toString(); |
| 85 } | 92 } |
| 86 } | 93 } |
| OLD | NEW |