blob: b390e9b8c2041de438db4762c4b35d495343075c [file] [log] [blame]
// Copyright (c) 2014, Google Inc. 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.
import 'dart:async';
import 'dart:io' as io;
import 'package:stagehand/stagehand.dart';
import 'package:stagehand/src/cli_app.dart';
import 'package:usage/usage_io.dart';
void main(List<String> args) {
var app = CliApp(generators, CliLogger());
try {
app.process(args).catchError((Object e, StackTrace st) {
if (e is ArgError) {
// These errors are expected.
} else {
print('Unexpected error: $e\n$st');
_sendException(, e, st).then((_) {
}).whenComplete(() {
// Always exit quickly after performing work. If the user has opted into
// analytics, the analytics I/O can cause the CLI to wait to terminate.
// This is annoying to the user, as the tool has already completed its
// work from their perspective.
} catch (e, st) {
print('Unexpected error: $e\n$st');
_sendException(, e, st);
Future _sendException(Analytics analytics, Object e, StackTrace st) {
// Sanitize (file:///Users/user/tmp/error.dart:3:13) to (error.dart:3:13).
var str = sanitizeStacktrace(st);
if (e != null) str = '${e.runtimeType}: $str';
return analytics.sendException(str, fatal: true);