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 /// Whether the schedule was finished executing at the time the error was | |
| 23 /// detected. | |
| 24 bool _scheduleWasDone; | |
| 25 | |
| 22 /// Creates a new [ScheduleError] wrapping [error]. The metadata in | 26 /// Creates a new [ScheduleError] wrapping [error]. The metadata in |
| 23 /// [AsyncError]s and [ScheduleError]s will be preserved. | 27 /// [AsyncError]s and [ScheduleError]s will be preserved. |
| 24 factory ScheduleError.from(Schedule schedule, error, {stackTrace, | 28 factory ScheduleError.from(Schedule schedule, error, {stackTrace, |
| 25 AsyncError cause, Task task}) { | 29 AsyncError cause, Task task}) { |
| 26 if (error is ScheduleError) { | 30 if (error is ScheduleError) { |
| 27 if (schedule == null) schedule = error.schedule; | 31 if (schedule == null) schedule = error.schedule; |
| 28 if (task == null) task = error.task; | 32 if (task == null) task = error.task; |
| 29 } | 33 } |
| 30 | 34 |
| 31 if (error is AsyncError) { | 35 if (error is AsyncError) { |
| 32 // Overwrite the explicit stack trace, because it probably came from a | 36 // Overwrite the explicit stack trace, because it probably came from a |
| 33 // rethrow in the first place. | 37 // rethrow in the first place. |
| 34 stackTrace = error.stackTrace; | 38 stackTrace = error.stackTrace; |
| 35 if (cause == null) cause = error.cause; | 39 if (cause == null) cause = error.cause; |
| 36 error = error.error; | 40 error = error.error; |
| 37 } | 41 } |
| 38 | 42 |
| 39 return new ScheduleError(schedule, error, stackTrace, cause, task); | 43 return new ScheduleError(schedule, error, stackTrace, cause, task); |
| 40 } | 44 } |
| 41 | 45 |
| 42 ScheduleError(this.schedule, error, stackTrace, AsyncError cause, this.task) | 46 ScheduleError(this.schedule, error, stackTrace, AsyncError cause, this.task) |
| 43 : super.withCause(error, stackTrace, cause); | 47 : super.withCause(error, stackTrace, cause) { |
|
Bob Nystrom
2013/02/11 22:30:19
Indent another two.
| |
| 48 _scheduleWasDone = schedule.done; | |
|
Bob Nystrom
2013/02/11 22:30:19
I'd prefer this to be final and in the initializat
| |
| 49 } | |
| 44 | 50 |
| 45 String toString() { | 51 String toString() { |
| 46 var result = new StringBuffer(); | 52 var result = new StringBuffer(); |
| 47 | 53 |
| 48 var errorString = error.toString(); | 54 var errorString = error.toString(); |
| 49 if (errorString.contains("\n")) { | 55 if (errorString.contains("\n")) { |
| 50 result.add('ScheduleError:\n'); | 56 result.add('ScheduleError:\n'); |
| 51 result.add(prefixLines(errorString.trim())); | 57 result.add(prefixLines(errorString.trim())); |
| 52 result.add("\n\n"); | 58 result.add("\n\n"); |
| 53 } else { | 59 } else { |
| 54 result.add('ScheduleError: "$errorString"\n'); | 60 result.add('ScheduleError: "$errorString"\n'); |
| 55 } | 61 } |
| 56 | 62 |
| 57 result.add('Stack trace:\n'); | 63 result.add('Stack trace:\n'); |
| 58 result.add(prefixLines(stackTrace.toString().trim())); | 64 result.add(prefixLines(stackTrace.toString().trim())); |
| 59 result.add("\n\n"); | 65 result.add("\n\n"); |
| 60 | 66 |
| 61 if (task != null) { | 67 if (task != null) { |
| 62 result.add('Error detected during task in queue "${task.queue}":\n'); | 68 result.add('Error detected during task in queue "${task.queue}":\n'); |
| 63 result.add(task.generateTree()); | 69 result.add(task.generateTree()); |
| 64 } else if (schedule.done) { | 70 } else if (_scheduleWasDone) { |
| 65 result.add('Error detected after all tasks in the queue had finished.'); | 71 result.add('Error detected after all tasks in the queue had finished.'); |
| 66 } else { | 72 } else { |
| 67 result.add('Error detected before the schedule started running'); | 73 result.add('Error detected before the schedule started running.'); |
| 68 } | 74 } |
| 69 | 75 |
| 70 return result.toString(); | 76 return result.toString(); |
| 71 } | 77 } |
| 72 } | 78 } |
| OLD | NEW |