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

Unified Diff: pkg/scheduled_test/lib/src/schedule_error.dart

Issue 12209073: Add a scheduled test library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make everything play nicely with the outside world. 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 side-by-side diff with in-line comments
Download patch
Index: pkg/scheduled_test/lib/src/schedule_error.dart
diff --git a/pkg/scheduled_test/lib/src/schedule_error.dart b/pkg/scheduled_test/lib/src/schedule_error.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0f97161a58a4407f42ea1a8d80f323a117a0498e
--- /dev/null
+++ b/pkg/scheduled_test/lib/src/schedule_error.dart
@@ -0,0 +1,72 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library schedule_error;
+
+import 'dart:async';
+
+import 'schedule.dart';
+import 'task.dart';
+import 'utils.dart';
+
+/// A wrapper for errors that occur during a scheduled test.
+class ScheduleError extends AsyncError {
+ /// The schedule during which this error occurred.
+ final Schedule schedule;
+
+ /// The task that was running when this error occurred. This may be `null` if
+ /// there was no such task.
+ final Task task;
+
+ /// Creates a new [ScheduleError] wrapping [error]. The metadata in
+ /// [AsyncError]s and [ScheduleError]s will be preserved.
+ factory ScheduleError.from(Schedule schedule, error, {stackTrace,
+ AsyncError cause, Task task}) {
+ if (error is ScheduleError) {
+ if (schedule == null) schedule = error.schedule;
+ if (task == null) task = error.task;
+ }
+
+ if (error is AsyncError) {
+ // Overwrite the explicit stack trace, because it probably came from a
+ // rethrow in the first place.
+ stackTrace = error.stackTrace;
+ if (cause == null) cause = error.cause;
+ error = error.error;
+ }
+
+ return new ScheduleError(schedule, error, stackTrace, cause, task);
+ }
+
+ ScheduleError(this.schedule, error, stackTrace, AsyncError cause, this.task)
+ : super.withCause(error, stackTrace, cause);
+
+ String toString() {
+ var result = new StringBuffer();
+
+ var errorString = error.toString();
+ if (errorString.contains("\n")) {
+ result.add('ScheduleError:\n');
+ result.add(prefixLines(errorString.trim()));
+ result.add("\n\n");
+ } else {
+ result.add('ScheduleError: "$errorString"\n');
+ }
+
+ result.add('Stack trace:\n');
+ result.add(prefixLines(stackTrace.toString().trim()));
+ result.add("\n\n");
+
+ if (task != null) {
+ result.add('Error detected during task in queue "${task.queue}":\n');
+ result.add(task.generateTree());
+ } else if (schedule.done) {
+ result.add('Error detected after all tasks in the queue had finished.');
+ } else {
+ result.add('Error detected before the schedule started running');
+ }
+
+ return result.toString();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698