common.dart 1.33 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'file_system.dart';
6
import 'platform.dart';
7

8
const int kDefaultObservatoryPort = 8100;
9

10 11 12
/// Return the absolute path of the user's home directory
String get homeDirPath {
  if (_homeDirPath == null) {
13 14 15
    _homeDirPath = platform.isWindows
        ? platform.environment['USERPROFILE']
        : platform.environment['HOME'];
16
    if (_homeDirPath != null)
17
      _homeDirPath = fs.path.absolute(_homeDirPath);
18 19 20 21 22
  }
  return _homeDirPath;
}
String _homeDirPath;

23 24 25 26
/// 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.
/// For example: network errors
27
void throwToolExit(String message, { int exitCode }) {
28
  throw new ToolExit(message, exitCode: exitCode);
29 30
}

31 32 33 34 35
/// 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.
/// For example: network errors
class ToolExit implements Exception {
36
  ToolExit(this.message, { this.exitCode });
37 38 39 40 41

  final String message;
  final int exitCode;

  @override
42
  String toString() => 'Exception: $message';
43
}