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

Side by Side Diff: lib/src/runner/browser/safari.dart

Issue 1091883002: More gracefully handle browser errors. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: merge Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « lib/src/runner/browser/phantom_js.dart ('k') | lib/src/runner/browser/server.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.runner.browser.safari; 5 library test.runner.browser.safari;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:path/path.dart' as p; 11 import 'package:path/path.dart' as p;
12 import 'package:stack_trace/stack_trace.dart';
12 13
13 import '../../util/io.dart'; 14 import '../../util/io.dart';
15 import '../../utils.dart';
16 import '../application_exception.dart';
14 import 'browser.dart'; 17 import 'browser.dart';
15 18
16 /// A class for running an instance of Safari. 19 /// A class for running an instance of Safari.
17 /// 20 ///
18 /// Any errors starting or running the process are reported through [onExit]. 21 /// Any errors starting or running the process are reported through [onExit].
19 class Safari implements Browser { 22 class Safari implements Browser {
20 /// The underlying process. 23 /// The underlying process.
21 Process _process; 24 Process _process;
22 25
23 Future get onExit => _onExitCompleter.future; 26 Future get onExit => _onExitCompleter.future;
(...skipping 28 matching lines...) Expand all
52 55
53 return Process.start(executable, [redirect]).then((process) { 56 return Process.start(executable, [redirect]).then((process) {
54 _process = process; 57 _process = process;
55 _onProcessStartedCompleter.complete(); 58 _onProcessStartedCompleter.complete();
56 59
57 // TODO(nweiz): the browser's standard output is almost always useless 60 // TODO(nweiz): the browser's standard output is almost always useless
58 // noise, but we should allow the user to opt in to seeing it. 61 // noise, but we should allow the user to opt in to seeing it.
59 return _process.exitCode; 62 return _process.exitCode;
60 }); 63 });
61 }).then((exitCode) { 64 }).then((exitCode) {
62 if (exitCode != 0) throw "Safari failed with exit code $exitCode."; 65 if (exitCode == 0) return null;
63 }).then(_onExitCompleter.complete) 66
64 .catchError(_onExitCompleter.completeError); 67 return UTF8.decodeStream(_process.stderr).then((error) {
68 throw new ApplicationException(
69 "Safari failed with exit code $exitCode:\n$error");
70 });
71 }).then(_onExitCompleter.complete).catchError((error, stackTrace) {
72 if (stackTrace == null) stackTrace = new Trace.current();
73 _onExitCompleter.completeError(
74 new ApplicationException(
75 "Failed to start Safari: ${getErrorMessage(error)}."),
76 stackTrace);
77 });
65 } 78 }
66 79
67 Future close() { 80 Future close() {
68 _onProcessStarted.then((_) => _process.kill()); 81 _onProcessStarted.then((_) => _process.kill());
69 82
70 // Swallow exceptions. The user should explicitly use [onExit] for these. 83 // Swallow exceptions. The user should explicitly use [onExit] for these.
71 return onExit.catchError((_) {}); 84 return onExit.catchError((_) {});
72 } 85 }
73 } 86 }
OLDNEW
« no previous file with comments | « lib/src/runner/browser/phantom_js.dart ('k') | lib/src/runner/browser/server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698