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

5 6 7
/// Throw a specialized exception for expected situations
/// where the tool should exit with a clear message to the user
/// and no stack trace unless the --verbose option is specified.
8
/// For example: network errors.
9
Never throwToolExit(String message, { int? exitCode }) {
10
  throw ToolExit(message, exitCode: exitCode);
11 12
}

13 14 15
/// Specialized exception for expected situations
/// where the tool should exit with a clear message to the user
/// and no stack trace unless the --verbose option is specified.
16
/// For example: network errors.
17
class ToolExit implements Exception {
18
  ToolExit(this.message, { this.exitCode });
19

20
  final String? message;
21
  final int? exitCode;
22 23

  @override
24
  String toString() => 'Exception: $message'; // TODO(ianh): Really this should say "Error".
25
}
26

27
/// Indicates to the linter that the given future is intentionally not awaited.
28 29 30 31 32 33 34 35
///
/// Has the same functionality as `unawaited` from `package:pedantic`.
///
/// In an async context, it is normally expected than all Futures are awaited,
/// and that is the basis of the lint unawaited_futures which is turned on for
/// the flutter_tools package. However, there are times where one or more
/// futures are intentionally not awaited. This function may be used to ignore a
/// particular future. It silences the unawaited_futures lint.
36
void unawaited(Future<void>? future) { }