Skip to content

Cleanup and improve error messages #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions webdev/bin/webdev.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:args/command_runner.dart';
import 'package:io/ansi.dart';
import 'package:io/io.dart';
import 'package:webdev/src/webdev_command_runner.dart';
import 'package:webdev/src/util.dart';

Future main(List<String> args) async {
try {
Expand All @@ -19,26 +20,28 @@ Future main(List<String> args) async {
print(' ');
print(e.usage);
exitCode = ExitCode.usage.code;
} on FileSystemException catch (e) {
print(yellow.wrap('$_boldApp could not run in the current directory.'));
print(e.message);
if (e.path != null) {
print(' ${e.path}');
}
exitCode = ExitCode.config.code;
} on PackageException catch (e) {
print(yellow.wrap('Could not run in the current directory.'));
print(yellow.wrap('$_boldApp could not run for this project.'));
for (var detail in e.details) {
print(detail.error);
print(yellow.wrap(detail.error));
if (detail.description != null) {
print(' ${detail.description}');
print(detail.description);
}
}

exitCode = ExitCode.config.code;
} on FileSystemException catch (e) {
print(yellow.wrap('Could not run in the current directory.'));
print(e.message);
if (e.path != null) {
print(' ${e.path}');
}
exitCode = ExitCode.config.code;
} on IsolateSpawnException catch (e) {
print(red.wrap('An unexpected exception has occurred.'));
print(red.wrap('$_boldApp failed with an unexpected exception.'));
print(e.message);
exitCode = ExitCode.software.code;
}
}

String get _boldApp => styleBold.wrap(appName);
17 changes: 9 additions & 8 deletions webdev/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class PackageExceptionDetails {
static const noPubspecLock = const PackageExceptionDetails._(
'`pubspec.lock` does not exist.',
description:
'Run `webdev` in a Dart package directory. Run `pub get` first.');
'Run `$appName` in a Dart package directory. Run `pub get` first.');

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

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

var version = buildRunner['version'] as String;
var buildRunnerVersion = new Version.parse(version);
if (!supportedBuildRunnerVersionRange.allows(buildRunnerVersion)) {
if (!supportedBuildRunnerVersionConstraint.allows(buildRunnerVersion)) {
var error = 'The `build_runner` version – $buildRunnerVersion – is not '
'within the supported range – $supportedBuildRunnerVersionRange.';
'within the allowed constraint – $supportedBuildRunnerVersionConstraint.';
issues.add(new PackageExceptionDetails._(error));
}
} else {
Expand Down
9 changes: 4 additions & 5 deletions webdev/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';

final supportedBuildRunnerVersionRange = new VersionRange(
min: new Version(0, 8, 0),
includeMin: true,
max: new Version(0, 9, 0),
includeMax: false);
const appName = 'webdev';

final supportedBuildRunnerVersionConstraint =
new VersionConstraint.parse('^0.8.0');

/// The path to the root directory of the SDK.
final String _sdkDir = (() {
Expand Down
3 changes: 2 additions & 1 deletion webdev/lib/src/webdev_command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import 'package:args/command_runner.dart';

import 'command/build_command.dart';
import 'command/serve_command.dart';
import 'util.dart';

export 'pubspec.dart' show PackageException;

Future<int> run(List<String> args) async {
var runner =
new CommandRunner<int>('webdev', 'A tool to develop Dart web projects.')
new CommandRunner<int>(appName, 'A tool to develop Dart web projects.')
..addCommand(new BuildCommand())
..addCommand(new ServeCommand());

Expand Down
2 changes: 1 addition & 1 deletion webdev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: webdev
version: 0.1.3+1
version: 0.1.4-dev
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/webdev
description: >-
Expand Down
78 changes: 25 additions & 53 deletions webdev/test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void main() {
var process = await _runWebDev(['build']);
var output = (await process.stdoutStream().join('\n')).trim();

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

Expand All @@ -58,29 +58,19 @@ A dependency on `build_runner` was not found.'''));
name: sample
''').create();

await d.file('pubspec.lock', '''
# Copy-pasted from a valid run
packages:
build_runner:
dependency: "direct main"
description:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "$version"
''').create();
await d.file('pubspec.lock', _pubspecLock(version: version)).create();

await d.file('.packages', '''
''').create();

var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

await expectLater(
process.stdout, emits('Could not run in the current directory.'));
process.stdout, emits('webdev could not run for this project.'));
await expectLater(
process.stdout,
emits('The `build_runner` version – $version – '
'is not within the supported range>=0.8.0 <0.9.0.'));
'is not within the allowed constraint^0.8.0.'));
await process.shouldExit(78);
});
}
Expand All @@ -91,7 +81,7 @@ packages:

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

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

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

expect(output, contains('Could not run in the current directory.'));
expect(output, contains('webdev could not run for this project.'));
expect(output,
contains('No pubspec.lock file found, please run "pub get" first.'));
await process.shouldExit(78);
Expand All @@ -116,23 +106,13 @@ name: sample
name: sample
''').create();

await d.file('pubspec.lock', '''
# Copy-pasted from a valid run
packages:
build_runner:
dependency: "direct main"
description:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.0"
''').create();
await d.file('pubspec.lock', _pubspecLock()).create();

var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

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

expect(output, contains('Could not run in the current directory.'));
expect(output, contains('webdev could not run for this project.'));
expect(output,
contains('No .packages file found, please run "pub get" first.'));
await process.shouldExit(78);
Expand All @@ -143,43 +123,23 @@ packages:
name: sample
''').create();

await d.file('pubspec.lock', '''
# Copy-pasted from a valid run
packages:
build_runner:
dependency: "direct main"
description:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.0"
''').create();
await d.file('pubspec.lock', _pubspecLock()).create();

await d.file('.packages', '').create();

var process = await _runWebDev(['build'], workingDirectory: d.sandbox);

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

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

// The isolate will fail - broken .packages file
expect(output, contains('Unable to spawn isolate'));
await process.shouldExit(70);
});

test('should fail if there has been a dependency change', () async {
await d.file('pubspec.lock', '''
# Copy-pasted from a valid run
packages:
build_runner:
dependency: "direct main"
description:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.0"
''').create();
await d.file('pubspec.lock', _pubspecLock()).create();

await d.file('.packages', '').create();

Expand All @@ -196,7 +156,7 @@ dependencies:

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

expect(output, contains('Could not run in the current directory.'));
expect(output, contains('webdev could not run for this project.'));
expect(
output,
contains(
Expand Down Expand Up @@ -228,6 +188,18 @@ dependencies:
}, timeout: const Timeout(const Duration(minutes: 5)));
}

String _pubspecLock({String version: '0.8.0'}) => '''
# Copy-pasted from a valid run
packages:
build_runner:
dependency: "direct main"
description:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "$version"
''';

/// Returns an environment map that includes `PUB_ENVIRONMENT`.
///
/// Maintains any existing values for this environment var.
Expand Down