Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: pkg/scheduled_test/lib/src/schedule_error.dart

Issue 12226103: Revert "Add built-in timeouts to scheduled_test." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /// The state of the schedule at the time the error was detected. 22 /// Whether the schedule was finished executing at the time the error was
23 final ScheduleState _stateWhenDetected; 23 /// detected.
24 final bool _scheduleWasDone;
24 25
25 /// Creates a new [ScheduleError] wrapping [error]. The metadata in 26 /// Creates a new [ScheduleError] wrapping [error]. The metadata in
26 /// [AsyncError]s and [ScheduleError]s will be preserved. 27 /// [AsyncError]s and [ScheduleError]s will be preserved.
27 factory ScheduleError.from(Schedule schedule, error, {stackTrace, 28 factory ScheduleError.from(Schedule schedule, error, {stackTrace,
28 AsyncError cause, Task task}) { 29 AsyncError cause, Task task}) {
29 if (error is ScheduleError) { 30 if (error is ScheduleError) {
30 if (schedule == null) schedule = error.schedule; 31 if (schedule == null) schedule = error.schedule;
31 if (task == null) task = error.task; 32 if (task == null) task = error.task;
32 } 33 }
33 34
34 if (error is AsyncError) { 35 if (error is AsyncError) {
35 // Overwrite the explicit stack trace, because it probably came from a 36 // Overwrite the explicit stack trace, because it probably came from a
36 // rethrow in the first place. 37 // rethrow in the first place.
37 stackTrace = error.stackTrace; 38 stackTrace = error.stackTrace;
38 if (cause == null) cause = error.cause; 39 if (cause == null) cause = error.cause;
39 error = error.error; 40 error = error.error;
40 } 41 }
41 42
42 return new ScheduleError(schedule, error, stackTrace, cause, task); 43 return new ScheduleError(schedule, error, stackTrace, cause, task);
43 } 44 }
44 45
45 ScheduleError(Schedule schedule, error, stackTrace, AsyncError cause, 46 ScheduleError(Schedule schedule, error, stackTrace, AsyncError cause,
46 this.task) 47 this.task)
47 : super.withCause(error, stackTrace, cause), 48 : super.withCause(error, stackTrace, cause),
48 this.schedule = schedule, 49 this.schedule = schedule,
49 this._stateWhenDetected = schedule.state; 50 this._scheduleWasDone = schedule.done;
50 51
51 String toString() { 52 String toString() {
52 var result = new StringBuffer(); 53 var result = new StringBuffer();
53 54
54 var errorString = error.toString(); 55 var errorString = error.toString();
55 if (errorString.contains("\n")) { 56 if (errorString.contains("\n")) {
56 result.add('ScheduleError:\n'); 57 result.add('ScheduleError:\n');
57 result.add(prefixLines(errorString.trim())); 58 result.add(prefixLines(errorString.trim()));
58 result.add("\n\n"); 59 result.add("\n\n");
59 } else { 60 } else {
60 result.add('ScheduleError: "$errorString"\n'); 61 result.add('ScheduleError: "$errorString"\n');
61 } 62 }
62 63
63 result.add('Stack trace:\n'); 64 result.add('Stack trace:\n');
64 result.add(prefixLines(stackTrace.toString().trim())); 65 result.add(prefixLines(stackTrace.toString().trim()));
65 result.add("\n\n"); 66 result.add("\n\n");
66 67
67 if (task != null) { 68 if (task != null) {
68 result.add('Error detected during task in queue "${task.queue}":\n'); 69 result.add('Error detected during task in queue "${task.queue}":\n');
69 result.add(task.generateTree()); 70 result.add(task.generateTree());
70 } else if (_stateWhenDetected == ScheduleState.DONE) { 71 } else if (_scheduleWasDone) {
71 result.add('Error detected after all tasks in the queue had finished.'); 72 result.add('Error detected after all tasks in the queue had finished.');
72 } else { // _stateWhenDetected == ScheduleState.SET_UP 73 } else {
73 result.add('Error detected before the schedule started running.'); 74 result.add('Error detected before the schedule started running.');
74 } 75 }
75 76
76 return result.toString(); 77 return result.toString();
77 } 78 }
78 } 79 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/lib/src/schedule.dart ('k') | pkg/scheduled_test/lib/src/substitute_future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698