Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library schedule_error; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'schedule.dart'; | |
| 10 import 'task.dart'; | |
| 11 import 'utils.dart'; | |
| 12 | |
| 13 /// A wrapper for errors that occur during a scheduled test. | |
| 14 class ScheduleError extends AsyncError { | |
| 15 /// The schedule during which this error occurred. | |
| 16 final Schedule schedule; | |
| 17 | |
| 18 /// The task that was running when this error occurred. This may be `null` if | |
| 19 /// there was no such task. | |
| 20 final Task task; | |
| 21 | |
| 22 /// Creates a new [ScheduleError] wrapping [error]. The metadata in | |
| 23 /// [AsyncError]s and [ScheduleError]s will be preserved. | |
| 24 factory ScheduleError.from(Schedule schedule, error, {stackTrace, | |
| 25 AsyncError cause, Task task}) { | |
| 26 if (error is ScheduleError) { | |
| 27 if (schedule == null) schedule = error.schedule; | |
| 28 if (task == null) task = error.task; | |
| 29 } | |
| 30 | |
| 31 if (error is AsyncError) { | |
| 32 // Overwrite the explicit stack trace, because it probably came from a | |
| 33 // rethrow in the first place. | |
| 34 stackTrace = error.stackTrace; | |
| 35 if (cause == null) cause = error.cause; | |
| 36 error = error.error; | |
| 37 } | |
| 38 | |
| 39 return new ScheduleError(schedule, error, stackTrace, cause, task); | |
| 40 } | |
| 41 | |
| 42 ScheduleError(this.schedule, error, stackTrace, AsyncError cause, this.task) | |
| 43 : super.withCause(error, stackTrace, cause); | |
| 44 | |
| 45 String toString() { | |
| 46 var result = new StringBuffer(); | |
| 47 | |
| 48 var errorString = error.toString(); | |
| 49 if (errorString.contains("\n")) { | |
| 50 result.add('ScheduleError:\n'); | |
| 51 result.add(prefixLines(errorString.trim())); | |
| 52 result.add("\n\n"); | |
| 53 } else { | |
| 54 result.add('ScheduleError: "$errorString"\n'); | |
| 55 } | |
| 56 | |
| 57 result.add('Stack trace:\n'); | |
| 58 result.add(prefixLines(stackTrace.toString().trim())); | |
|
Bob Nystrom
2013/02/08 16:15:37
Might be cool to borrow some of the stacktrace cle
nweiz
2013/02/08 22:14:38
That would be a nice thing to move into its own pa
| |
| 59 result.add("\n\n"); | |
| 60 | |
| 61 if (task != null) { | |
| 62 result.add('Error detected during task in queue "${task.queue}":\n'); | |
| 63 result.add(task.generateTree()); | |
| 64 } else if (schedule.done) { | |
| 65 result.add('Error detected after all tasks in the queue had finished.'); | |
| 66 } else { | |
| 67 result.add('Error detected before the schedule started running'); | |
| 68 } | |
| 69 | |
| 70 return result.toString(); | |
| 71 } | |
| 72 } | |
| OLD | NEW |