error.dart 1.74 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io' show stderr;

/// Standard error thrown by Flutter Driver API.
class DriverError extends Error {
9 10
  /// Create an error with a [message] and (optionally) the [originalError] and
  /// [originalStackTrace] that caused it.
11 12 13 14 15
  DriverError(this.message, [this.originalError, this.originalStackTrace]);

  /// Human-readable error message.
  final String message;

16
  /// The error object that was caught and wrapped by this error object, if any.
17
  final dynamic originalError;
18

19
  /// The stack trace that was caught and wrapped by this error object, if any.
20 21
  final dynamic originalStackTrace;

22
  @override
23
  String toString() {
24 25
    if (originalError == null)
      return 'DriverError: $message\n';
26 27
    return '''
DriverError: $message
28 29 30
Original error: $originalError
Original stack trace:
$originalStackTrace
31
''';
32
  }
33 34
}

35
/// Signature for [driverLog].
36
///
37 38
/// The first argument is a string representing the source of the message,
/// typically the class name or library name calling the method.
39
///
40 41
/// The second argument is the message being logged.
typedef DriverLogCallback = void Function(String source, String message);
42

43 44 45 46 47 48 49 50 51 52 53 54 55
/// Print the given message to the console.
///
/// The first argument is a string representing the source of the message.
///
/// The second argument is the message being logged.
///
/// This can be set to a different callback to override the handling of log
/// messages from the driver subsystem.
///
/// The default implementation prints `"$source: $message"` to stderr.
DriverLogCallback driverLog = (String source, String message) {
  stderr.writeln('$source: $message');
};