Skip to content

Commit cd2559b

Browse files
committed
Improve error output, mention webdev, etc
1 parent 47a6560 commit cd2559b

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

webdev/bin/webdev.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:args/command_runner.dart';
1010
import 'package:io/ansi.dart';
1111
import 'package:io/io.dart';
1212
import 'package:webdev/src/webdev_command_runner.dart';
13+
import 'package:webdev/src/util.dart';
1314

1415
Future main(List<String> args) async {
1516
try {
@@ -19,26 +20,28 @@ Future main(List<String> args) async {
1920
print(' ');
2021
print(e.usage);
2122
exitCode = ExitCode.usage.code;
23+
} on FileSystemException catch (e) {
24+
print(yellow.wrap('$_boldApp could not run in the current directory.'));
25+
print(e.message);
26+
if (e.path != null) {
27+
print(' ${e.path}');
28+
}
29+
exitCode = ExitCode.config.code;
2230
} on PackageException catch (e) {
23-
print(yellow.wrap('Could not run in the current directory.'));
31+
print(yellow.wrap('$_boldApp could not run for this project.'));
2432
for (var detail in e.details) {
25-
print(detail.error);
33+
print(yellow.wrap(detail.error));
2634
if (detail.description != null) {
27-
print(' ${detail.description}');
35+
print(detail.description);
2836
}
2937
}
3038

31-
exitCode = ExitCode.config.code;
32-
} on FileSystemException catch (e) {
33-
print(yellow.wrap('Could not run in the current directory.'));
34-
print(e.message);
35-
if (e.path != null) {
36-
print(' ${e.path}');
37-
}
3839
exitCode = ExitCode.config.code;
3940
} on IsolateSpawnException catch (e) {
40-
print(red.wrap('An unexpected exception has occurred.'));
41+
print(red.wrap('$_boldApp failed with an unexpected exception.'));
4142
print(e.message);
4243
exitCode = ExitCode.software.code;
4344
}
4445
}
46+
47+
String get _boldApp => styleBold.wrap(appName);

webdev/lib/src/pubspec.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ class PackageExceptionDetails {
2525
static const noPubspecLock = const PackageExceptionDetails._(
2626
'`pubspec.lock` does not exist.',
2727
description:
28-
'Run `webdev` in a Dart package directory. Run `pub get` first.');
28+
'Run `$appName` in a Dart package directory. Run `pub get` first.');
2929

30-
static const noBuildRunnerDep = const PackageExceptionDetails._(
31-
'A dependency on `build_runner` was not found.',
32-
description:
33-
'You must have a dependency on `build_runner` in `pubspec.yaml`. '
34-
'It can be in either `dependencies` or `dev_dependencies`.');
30+
static final noBuildRunnerDep = new PackageExceptionDetails._(
31+
'You must have a dependency on `build_runner` in `pubspec.yaml`.',
32+
description: '''
33+
# pubspec.yaml
34+
dev_dependencies:
35+
build_runner: $supportedBuildRunnerVersionConstraint''');
3536

3637
@override
3738
String toString() => [error, description].join('\n');
@@ -81,9 +82,9 @@ Future checkPubspecLock() async {
8182

8283
var version = buildRunner['version'] as String;
8384
var buildRunnerVersion = new Version.parse(version);
84-
if (!supportedBuildRunnerVersionRange.allows(buildRunnerVersion)) {
85+
if (!supportedBuildRunnerVersionConstraint.allows(buildRunnerVersion)) {
8586
var error = 'The `build_runner` version – $buildRunnerVersion – is not '
86-
'within the supported range – $supportedBuildRunnerVersionRange.';
87+
'within the allowed constraint – $supportedBuildRunnerVersionConstraint.';
8788
issues.add(new PackageExceptionDetails._(error));
8889
}
8990
} else {

webdev/lib/src/util.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import 'dart:io';
77
import 'package:path/path.dart' as p;
88
import 'package:pub_semver/pub_semver.dart';
99

10-
final supportedBuildRunnerVersionRange = new VersionRange(
11-
min: new Version(0, 8, 0),
12-
includeMin: true,
13-
max: new Version(0, 9, 0),
14-
includeMax: false);
10+
const appName = 'webdev';
11+
12+
final supportedBuildRunnerVersionConstraint =
13+
new VersionConstraint.parse('^0.8.0');
1514

1615
/// The path to the root directory of the SDK.
1716
final String _sdkDir = (() {

webdev/lib/src/webdev_command_runner.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import 'package:args/command_runner.dart';
88

99
import 'command/build_command.dart';
1010
import 'command/serve_command.dart';
11+
import 'util.dart';
1112

1213
export 'pubspec.dart' show PackageException;
1314

1415
Future<int> run(List<String> args) async {
1516
var runner =
16-
new CommandRunner<int>('webdev', 'A tool to develop Dart web projects.')
17+
new CommandRunner<int>(appName, 'A tool to develop Dart web projects.')
1718
..addCommand(new BuildCommand())
1819
..addCommand(new ServeCommand());
1920

webdev/test/integration_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ void main() {
4646
var process = await _runWebDev(['build']);
4747
var output = (await process.stdoutStream().join('\n')).trim();
4848

49-
expect(output, contains(r'''Could not run in the current directory.
50-
A dependency on `build_runner` was not found.'''));
49+
expect(output, contains(r'''webdev could not run for this project.
50+
You must have a dependency on `build_runner` in `pubspec.yaml`.'''));
5151
await process.shouldExit(78);
5252
});
5353

@@ -66,11 +66,11 @@ name: sample
6666
var process = await _runWebDev(['build'], workingDirectory: d.sandbox);
6767

6868
await expectLater(
69-
process.stdout, emits('Could not run in the current directory.'));
69+
process.stdout, emits('webdev could not run for this project.'));
7070
await expectLater(
7171
process.stdout,
7272
emits('The `build_runner` version – $version – '
73-
'is not within the supported range>=0.8.0 <0.9.0.'));
73+
'is not within the allowed constraint^0.8.0.'));
7474
await process.shouldExit(78);
7575
});
7676
}
@@ -81,7 +81,7 @@ name: sample
8181

8282
var output = await process.stdoutStream().join('\n');
8383

84-
expect(output, contains('Could not run in the current directory.'));
84+
expect(output, contains('webdev could not run for this project.'));
8585
expect(output, contains('Could not find a file named "pubspec.yaml"'));
8686
await process.shouldExit(78);
8787
});
@@ -95,7 +95,7 @@ name: sample
9595

9696
var output = await process.stdoutStream().join('\n');
9797

98-
expect(output, contains('Could not run in the current directory.'));
98+
expect(output, contains('webdev could not run for this project.'));
9999
expect(output,
100100
contains('No pubspec.lock file found, please run "pub get" first.'));
101101
await process.shouldExit(78);
@@ -112,7 +112,7 @@ name: sample
112112

113113
var output = await process.stdoutStream().join('\n');
114114

115-
expect(output, contains('Could not run in the current directory.'));
115+
expect(output, contains('webdev could not run for this project.'));
116116
expect(output,
117117
contains('No .packages file found, please run "pub get" first.'));
118118
await process.shouldExit(78);
@@ -131,7 +131,7 @@ name: sample
131131

132132
var output = await process.stdoutStream().join('\n');
133133

134-
expect(output, contains('An unexpected exception has occurred.'));
134+
expect(output, contains('webdev failed with an unexpected exception.'));
135135

136136
// The isolate will fail - broken .packages file
137137
expect(output, contains('Unable to spawn isolate'));
@@ -156,7 +156,7 @@ dependencies:
156156

157157
var output = await process.stdoutStream().join('\n');
158158

159-
expect(output, contains('Could not run in the current directory.'));
159+
expect(output, contains('webdev could not run for this project.'));
160160
expect(
161161
output,
162162
contains(

0 commit comments

Comments
 (0)