| 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 15 matching lines...) Expand all Loading... |
| 26 /// The task that was running when this error occurred. This may be `null` if | 26 /// The task that was running when this error occurred. This may be `null` if |
| 27 /// there was no such task. | 27 /// there was no such task. |
| 28 final Task task; | 28 final Task task; |
| 29 | 29 |
| 30 /// The task queue that was running when this error occured. This may be | 30 /// The task queue that was running when this error occured. This may be |
| 31 /// `null` if there was no such queue. | 31 /// `null` if there was no such queue. |
| 32 final TaskQueue queue; | 32 final TaskQueue queue; |
| 33 | 33 |
| 34 /// The descriptions of out-of-band callbacks that were pending when this | 34 /// The descriptions of out-of-band callbacks that were pending when this |
| 35 /// error occurred. | 35 /// error occurred. |
| 36 final Iterable<String> pendingCallbacks; | 36 final Iterable<PendingCallback> pendingCallbacks; |
| 37 | 37 |
| 38 /// The state of the schedule at the time the error was detected. | 38 /// The state of the schedule at the time the error was detected. |
| 39 final ScheduleState _stateWhenDetected; | 39 final ScheduleState _stateWhenDetected; |
| 40 | 40 |
| 41 int get hashCode => schedule.hashCode ^ task.hashCode ^ queue.hashCode ^ | 41 int get hashCode => schedule.hashCode ^ task.hashCode ^ queue.hashCode ^ |
| 42 _stateWhenDetected.hashCode ^ error.hashCode ^ stackTrace.hashCode; | 42 _stateWhenDetected.hashCode ^ error.hashCode ^ stackTrace.hashCode; |
| 43 | 43 |
| 44 /// Creates a new [ScheduleError] wrapping [error]. The metadata in | 44 /// Creates a new [ScheduleError] wrapping [error]. The metadata in |
| 45 /// [ScheduleError]s will be preserved. | 45 /// [ScheduleError]s will be preserved. |
| 46 factory ScheduleError.from(Schedule schedule, error, | 46 factory ScheduleError.from(Schedule schedule, error, |
| 47 {StackTrace stackTrace}) { | 47 {StackTrace stackTrace}) { |
| 48 if (error is ScheduleError) return error; | 48 if (error is ScheduleError) return error; |
| 49 | 49 |
| 50 var attachedTrace = getAttachedStackTrace(error); | 50 var attachedTrace = getAttachedStackTrace(error); |
| 51 if (attachedTrace != null) { | 51 if (attachedTrace != null) { |
| 52 // Overwrite the explicit stack trace, because it probably came from a | 52 // Overwrite the explicit stack trace, because it probably came from a |
| 53 // rethrow in the first place. | 53 // rethrow in the first place. |
| 54 stackTrace = attachedTrace; | 54 stackTrace = attachedTrace; |
| 55 } | 55 } |
| 56 | 56 |
| 57 if (schedule.captureStackTraces && stackTrace == null) { | 57 if (stackTrace == null) stackTrace = new Trace.current(); |
| 58 stackTrace = new Trace.current(); | |
| 59 } | |
| 60 | |
| 61 return new ScheduleError(schedule, error, stackTrace); | 58 return new ScheduleError(schedule, error, stackTrace); |
| 62 } | 59 } |
| 63 | 60 |
| 64 // TODO(floitsch): restore StackTrace type when it has been integrated into | 61 // TODO(floitsch): restore StackTrace type when it has been integrated into |
| 65 // the core libraries. | 62 // the core libraries. |
| 66 ScheduleError(Schedule schedule, error, var stackTrace) | 63 ScheduleError(Schedule schedule, error, var stackTrace) |
| 67 : error = error, | 64 : error = error, |
| 68 stackTrace = stackTrace, | 65 stackTrace = stackTrace, |
| 69 schedule = schedule, | 66 schedule = schedule, |
| 70 task = schedule.currentTask, | 67 task = schedule.currentTask, |
| 71 queue = schedule.currentQueue, | 68 queue = schedule.currentQueue, |
| 72 pendingCallbacks = schedule.currentQueue == null ? <String>[] | 69 pendingCallbacks = schedule.currentQueue == null ? <PendingCallback>[] |
| 73 : schedule.currentQueue.pendingCallbacks.toList(), | 70 : schedule.currentQueue.pendingCallbacks.toList(), |
| 74 _stateWhenDetected = schedule.state; | 71 _stateWhenDetected = schedule.state; |
| 75 | 72 |
| 76 bool operator ==(other) => other is ScheduleError && task == other.task && | 73 bool operator ==(other) => other is ScheduleError && task == other.task && |
| 77 queue == other.queue && _stateWhenDetected == other._stateWhenDetected && | 74 queue == other.queue && _stateWhenDetected == other._stateWhenDetected && |
| 78 error == other.error && stackTrace == other.stackTrace; | 75 error == other.error && stackTrace == other.stackTrace; |
| 79 | 76 |
| 80 String toString() { | 77 String toString() { |
| 81 var result = new StringBuffer(); | 78 var result = new StringBuffer(); |
| 82 | 79 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 105 result.write('Error detected when waiting for out-of-band callbacks in ' | 102 result.write('Error detected when waiting for out-of-band callbacks in ' |
| 106 'queue "$queue".'); | 103 'queue "$queue".'); |
| 107 } else { // _stateWhenDetected == ScheduleState.SET_UP | 104 } else { // _stateWhenDetected == ScheduleState.SET_UP |
| 108 result.write('Error detected before the schedule started running.'); | 105 result.write('Error detected before the schedule started running.'); |
| 109 } | 106 } |
| 110 | 107 |
| 111 if (!pendingCallbacks.isEmpty) { | 108 if (!pendingCallbacks.isEmpty) { |
| 112 result.write("\n\n"); | 109 result.write("\n\n"); |
| 113 result.writeln("Pending out-of-band callbacks:"); | 110 result.writeln("Pending out-of-band callbacks:"); |
| 114 for (var callback in pendingCallbacks) { | 111 for (var callback in pendingCallbacks) { |
| 115 result.writeln(prefixLines(callback, firstPrefix: "* ")); | 112 result.writeln(prefixLines(callback.toString(), firstPrefix: "* ")); |
| 116 } | 113 } |
| 117 } | 114 } |
| 118 | 115 |
| 119 return result.toString().trim(); | 116 return result.toString().trim(); |
| 120 } | 117 } |
| 121 } | 118 } |
| OLD | NEW |