| 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 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 if (error is ScheduleError) return error; | 43 if (error is ScheduleError) return error; |
| 44 | 44 |
| 45 if (error is AsyncError) { | 45 if (error is AsyncError) { |
| 46 // Overwrite the explicit stack trace, because it probably came from a | 46 // Overwrite the explicit stack trace, because it probably came from a |
| 47 // rethrow in the first place. | 47 // rethrow in the first place. |
| 48 stackTrace = error.stackTrace; | 48 stackTrace = error.stackTrace; |
| 49 if (cause == null) cause = error.cause; | 49 if (cause == null) cause = error.cause; |
| 50 error = error.error; | 50 error = error.error; |
| 51 } | 51 } |
| 52 | 52 |
| 53 if (stackTrace == null) { | 53 if (schedule.captureStackTraces && stackTrace == null) { |
| 54 try { | 54 stackTrace = new Trace.current(); |
| 55 throw ''; | |
| 56 } catch (_, thrownStackTrace) { | |
| 57 stackTrace = thrownStackTrace; | |
| 58 } | |
| 59 } | 55 } |
| 60 | 56 |
| 61 return new ScheduleError(schedule, error, stackTrace, cause); | 57 return new ScheduleError(schedule, error, stackTrace, cause); |
| 62 } | 58 } |
| 63 | 59 |
| 64 ScheduleError(Schedule schedule, error, StackTrace stackTrace, | 60 ScheduleError(Schedule schedule, error, StackTrace stackTrace, |
| 65 AsyncError cause) | 61 AsyncError cause) |
| 66 : super.withCause(error, stackTrace, cause), | 62 : super.withCause(error, stackTrace, cause), |
| 67 schedule = schedule, | 63 schedule = schedule, |
| 68 task = schedule.currentTask, | 64 task = schedule.currentTask, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 81 | 77 |
| 82 var errorString = error.toString(); | 78 var errorString = error.toString(); |
| 83 if (errorString.contains("\n")) { | 79 if (errorString.contains("\n")) { |
| 84 result.write('ScheduleError:\n'); | 80 result.write('ScheduleError:\n'); |
| 85 result.write(prefixLines(errorString.trim())); | 81 result.write(prefixLines(errorString.trim())); |
| 86 result.write("\n\n"); | 82 result.write("\n\n"); |
| 87 } else { | 83 } else { |
| 88 result.write('ScheduleError: "$errorString"\n'); | 84 result.write('ScheduleError: "$errorString"\n'); |
| 89 } | 85 } |
| 90 | 86 |
| 91 result.write('Stack trace:\n'); | 87 if (stackTrace != null) { |
| 92 result.write(prefixLines(terseTraceString(stackTrace))); | 88 result.write('Stack trace:\n'); |
| 93 result.write("\n\n"); | 89 result.write(prefixLines(terseTraceString(stackTrace))); |
| 90 result.write("\n\n"); |
| 91 } |
| 94 | 92 |
| 95 if (task != null) { | 93 if (task != null) { |
| 96 result.write('Error detected during task in queue "$queue":\n'); | 94 result.write('Error detected during task in queue "$queue":\n'); |
| 97 result.write(task.generateTree()); | 95 result.write(task.generateTree()); |
| 98 } else if (_stateWhenDetected == ScheduleState.DONE) { | 96 } else if (_stateWhenDetected == ScheduleState.DONE) { |
| 99 result.write('Error detected after all tasks in the schedule had ' | 97 result.write('Error detected after all tasks in the schedule had ' |
| 100 'finished.'); | 98 'finished.'); |
| 101 } else if (_stateWhenDetected == ScheduleState.RUNNING) { | 99 } else if (_stateWhenDetected == ScheduleState.RUNNING) { |
| 102 result.write('Error detected when waiting for out-of-band callbacks in ' | 100 result.write('Error detected when waiting for out-of-band callbacks in ' |
| 103 'queue "$queue".'); | 101 'queue "$queue".'); |
| 104 } else { // _stateWhenDetected == ScheduleState.SET_UP | 102 } else { // _stateWhenDetected == ScheduleState.SET_UP |
| 105 result.write('Error detected before the schedule started running.'); | 103 result.write('Error detected before the schedule started running.'); |
| 106 } | 104 } |
| 107 | 105 |
| 108 if (!pendingCallbacks.isEmpty) { | 106 if (!pendingCallbacks.isEmpty) { |
| 109 result.write("\n\n"); | 107 result.write("\n\n"); |
| 110 result.writeln("Pending out-of-band callbacks:"); | 108 result.writeln("Pending out-of-band callbacks:"); |
| 111 for (var callback in pendingCallbacks) { | 109 for (var callback in pendingCallbacks) { |
| 112 result.writeln(prefixLines(callback, firstPrefix: "* ")); | 110 result.writeln(prefixLines(callback, firstPrefix: "* ")); |
| 113 } | 111 } |
| 114 } | 112 } |
| 115 | 113 |
| 116 return result.toString().trim(); | 114 return result.toString().trim(); |
| 117 } | 115 } |
| 118 } | 116 } |
| OLD | NEW |