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 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| 11 import '../scheduled_test.dart' show captureStackTraces; | |
| 11 import 'schedule.dart'; | 12 import 'schedule.dart'; |
| 12 import 'task.dart'; | 13 import 'task.dart'; |
| 13 import 'utils.dart'; | 14 import 'utils.dart'; |
| 14 | 15 |
| 15 /// A wrapper for errors that occur during a scheduled test. | 16 /// A wrapper for errors that occur during a scheduled test. |
| 16 class ScheduleError extends AsyncError { | 17 class ScheduleError extends AsyncError { |
| 17 /// The schedule during which this error occurred. | 18 /// The schedule during which this error occurred. |
| 18 final Schedule schedule; | 19 final Schedule schedule; |
| 19 | 20 |
| 20 /// The task that was running when this error occurred. This may be `null` if | 21 /// The task that was running when this error occurred. This may be `null` if |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 43 if (error is ScheduleError) return error; | 44 if (error is ScheduleError) return error; |
| 44 | 45 |
| 45 if (error is AsyncError) { | 46 if (error is AsyncError) { |
| 46 // Overwrite the explicit stack trace, because it probably came from a | 47 // Overwrite the explicit stack trace, because it probably came from a |
| 47 // rethrow in the first place. | 48 // rethrow in the first place. |
| 48 stackTrace = error.stackTrace; | 49 stackTrace = error.stackTrace; |
| 49 if (cause == null) cause = error.cause; | 50 if (cause == null) cause = error.cause; |
| 50 error = error.error; | 51 error = error.error; |
| 51 } | 52 } |
| 52 | 53 |
| 53 if (stackTrace == null) { | 54 if (captureStackTraces && stackTrace == null) { |
| 54 try { | 55 try { |
| 55 throw ''; | 56 throw ''; |
| 56 } catch (_, thrownStackTrace) { | 57 } catch (_, thrownStackTrace) { |
| 57 stackTrace = thrownStackTrace; | 58 stackTrace = thrownStackTrace; |
|
nweiz
2013/04/09 21:25:58
While you're at it, change this to use [Trace.capt
Bob Nystrom
2013/04/10 21:52:00
Trace.current()? Done.
| |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 return new ScheduleError(schedule, error, stackTrace, cause); | 62 return new ScheduleError(schedule, error, stackTrace, cause); |
| 62 } | 63 } |
| 63 | 64 |
| 64 ScheduleError(Schedule schedule, error, StackTrace stackTrace, | 65 ScheduleError(Schedule schedule, error, StackTrace stackTrace, |
| 65 AsyncError cause) | 66 AsyncError cause) |
| 66 : super.withCause(error, stackTrace, cause), | 67 : super.withCause(error, stackTrace, cause), |
| 67 schedule = schedule, | 68 schedule = schedule, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 81 | 82 |
| 82 var errorString = error.toString(); | 83 var errorString = error.toString(); |
| 83 if (errorString.contains("\n")) { | 84 if (errorString.contains("\n")) { |
| 84 result.write('ScheduleError:\n'); | 85 result.write('ScheduleError:\n'); |
| 85 result.write(prefixLines(errorString.trim())); | 86 result.write(prefixLines(errorString.trim())); |
| 86 result.write("\n\n"); | 87 result.write("\n\n"); |
| 87 } else { | 88 } else { |
| 88 result.write('ScheduleError: "$errorString"\n'); | 89 result.write('ScheduleError: "$errorString"\n'); |
| 89 } | 90 } |
| 90 | 91 |
| 91 result.write('Stack trace:\n'); | 92 if (stackTrace != null) { |
| 92 result.write(prefixLines(terseTraceString(stackTrace))); | 93 result.write('Stack trace:\n'); |
| 93 result.write("\n\n"); | 94 result.write(prefixLines(terseTraceString(stackTrace))); |
| 95 result.write("\n\n"); | |
| 96 } | |
| 94 | 97 |
| 95 if (task != null) { | 98 if (task != null) { |
| 96 result.write('Error detected during task in queue "$queue":\n'); | 99 result.write('Error detected during task in queue "$queue":\n'); |
| 97 result.write(task.generateTree()); | 100 result.write(task.generateTree()); |
| 98 } else if (_stateWhenDetected == ScheduleState.DONE) { | 101 } else if (_stateWhenDetected == ScheduleState.DONE) { |
| 99 result.write('Error detected after all tasks in the schedule had ' | 102 result.write('Error detected after all tasks in the schedule had ' |
| 100 'finished.'); | 103 'finished.'); |
| 101 } else if (_stateWhenDetected == ScheduleState.RUNNING) { | 104 } else if (_stateWhenDetected == ScheduleState.RUNNING) { |
| 102 result.write('Error detected when waiting for out-of-band callbacks in ' | 105 result.write('Error detected when waiting for out-of-band callbacks in ' |
| 103 'queue "$queue".'); | 106 'queue "$queue".'); |
| 104 } else { // _stateWhenDetected == ScheduleState.SET_UP | 107 } else { // _stateWhenDetected == ScheduleState.SET_UP |
| 105 result.write('Error detected before the schedule started running.'); | 108 result.write('Error detected before the schedule started running.'); |
| 106 } | 109 } |
| 107 | 110 |
| 108 if (!pendingCallbacks.isEmpty) { | 111 if (!pendingCallbacks.isEmpty) { |
| 109 result.write("\n\n"); | 112 result.write("\n\n"); |
| 110 result.writeln("Pending out-of-band callbacks:"); | 113 result.writeln("Pending out-of-band callbacks:"); |
| 111 for (var callback in pendingCallbacks) { | 114 for (var callback in pendingCallbacks) { |
| 112 result.writeln(prefixLines(callback, firstPrefix: "* ")); | 115 result.writeln(prefixLines(callback, firstPrefix: "* ")); |
| 113 } | 116 } |
| 114 } | 117 } |
| 115 | 118 |
| 116 return result.toString().trim(); | 119 return result.toString().trim(); |
| 117 } | 120 } |
| 118 } | 121 } |
| OLD | NEW |