Skip to content

Commit 8208861

Browse files
authored
Emit exit code 66 for missing path dependencies (#1748)
Emit exit code 66 for missing path dependencies Closes #1747
1 parent f905418 commit 8208861

File tree

9 files changed

+30
-15
lines changed

9 files changed

+30
-15
lines changed

lib/src/command_runner.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import 'http.dart';
3030
import 'io.dart';
3131
import 'log.dart' as log;
3232
import 'sdk.dart' as sdk;
33-
import 'solver/version_solver.dart';
3433
import 'utils.dart';
3534

3635
class PubCommandRunner extends CommandRunner {
@@ -230,15 +229,20 @@ and include the logs in an issue on https://github.com/dart-lang/pub/issues/new
230229
/// Returns the appropriate exit code for [exception], falling back on 1 if no
231230
/// appropriate exit code could be found.
232231
int _chooseExitCode(exception) {
233-
while (exception is WrappedException) exception = exception.innerError;
232+
while (exception is WrappedException && exception.innerError is Exception) {
233+
exception = exception.innerError;
234+
}
234235

235236
if (exception is HttpException ||
236237
exception is http.ClientException ||
237238
exception is SocketException ||
238239
exception is TlsException ||
239240
exception is PubHttpException ||
240-
exception is DependencyNotFoundException) {
241+
exception is git.GitException ||
242+
exception is PackageNotFoundException) {
241243
return exit_codes.UNAVAILABLE;
244+
} else if (exception is FileSystemException || exception is FileException) {
245+
return exit_codes.NO_INPUT;
242246
} else if (exception is FormatException || exception is DataException) {
243247
return exit_codes.DATA;
244248
} else if (exception is UsageException) {

lib/src/solver/version_solver.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,15 @@ class DescriptionMismatchException extends SolveFailure {
469469
///
470470
/// Unlike [PackageNotFoundException], this includes information about the
471471
/// dependent packages requesting the missing one.
472-
class DependencyNotFoundException extends SolveFailure {
473-
final PackageNotFoundException _innerException;
474-
String get _message => "${_innerException.message}\nDepended on by";
472+
class DependencyNotFoundException extends SolveFailure
473+
implements WrappedException {
474+
final PackageNotFoundException innerError;
475+
Chain get innerChain => innerError.innerChain;
476+
477+
String get _message => "${innerError.message}\nDepended on by";
475478

476479
DependencyNotFoundException(
477-
String package, this._innerException, Iterable<Dependency> dependencies)
480+
String package, this.innerError, Iterable<Dependency> dependencies)
478481
: super(package, dependencies);
479482

480483
/// The failure isn't because of the version of description of the package,

lib/src/source/path.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class BoundPathSource extends BoundSource {
175175
}
176176

177177
throw new PackageNotFoundException(
178-
'Could not find package $name at "$dir".');
178+
'Could not find package $name at "$dir".',
179+
new FileException('$dir does not exist.', dir));
179180
}
180181
}

test/get/path/no_pubspec_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:test/test.dart';
66

77
import 'package:path/path.dart' as path;
8+
import 'package:pub/src/exit_codes.dart' as exit_codes;
89

910
import '../../descriptor.dart' as d;
1011
import '../../test_pub.dart';
@@ -23,6 +24,7 @@ main() {
2324

2425
await pubGet(
2526
error: new RegExp(r'Could not find a file named "pubspec.yaml" '
26-
r'in "[^\n]*"\.'));
27+
r'in "[^\n]*"\.'),
28+
exitCode: exit_codes.NO_INPUT);
2729
});
2830
}

test/get/path/nonexistent_dir_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ main() {
2323
await pubGet(error: """
2424
Could not find package foo at "$badPath".
2525
Depended on by:
26-
- myapp""", exitCode: exit_codes.UNAVAILABLE);
26+
- myapp""", exitCode: exit_codes.NO_INPUT);
2727
});
2828
}

test/global/activate/missing_git_repo_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import 'package:test/test.dart';
66

7+
import 'package:pub/src/exit_codes.dart' as exit_codes;
8+
79
import '../../test_pub.dart';
810

911
main() {
@@ -13,6 +15,6 @@ main() {
1315
await runPub(
1416
args: ["global", "activate", "-sgit", "../nope.git"],
1517
error: contains("repository '../nope.git' does not exist"),
16-
exitCode: 1);
18+
exitCode: exit_codes.UNAVAILABLE);
1719
});
1820
}

test/global/run/missing_path_package_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:path/path.dart' as p;
66
import 'package:test/test.dart';
77

8+
import 'package:pub/src/exit_codes.dart' as exit_codes;
89
import 'package:pub/src/io.dart';
910

1011
import '../../descriptor.dart' as d;
@@ -25,6 +26,6 @@ main() {
2526
var path = canonicalize(p.join(d.sandbox, "foo"));
2627
expect(pub.stderr,
2728
emits('Could not find a file named "pubspec.yaml" in "$path".'));
28-
await pub.shouldExit(1);
29+
await pub.shouldExit(exit_codes.NO_INPUT);
2930
});
3031
}

test/list_package_dirs/missing_pubspec_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE d.file.
44

5+
import 'package:path/path.dart' as path;
56
import 'package:test/test.dart';
67

7-
import 'package:path/path.dart' as path;
8+
import 'package:pub/src/exit_codes.dart' as exit_codes;
89
import 'package:pub/src/io.dart';
910

1011
import '../descriptor.dart' as d;
@@ -22,6 +23,6 @@ main() {
2223
"error": 'Could not find a file named "pubspec.yaml" in "'
2324
'${canonicalize(path.join(d.sandbox, appPath))}".',
2425
"path": canonicalize(path.join(d.sandbox, appPath, "pubspec.yaml"))
25-
}, exitCode: 1);
26+
}, exitCode: exit_codes.NO_INPUT);
2627
});
2728
}

test/pub_get_and_upgrade_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ main() {
1717

1818
await pubCommand(command,
1919
error: new RegExp(r'Could not find a file named "pubspec.yaml" '
20-
r'in "[^\n]*"\.'));
20+
r'in "[^\n]*"\.'),
21+
exitCode: exit_codes.NO_INPUT);
2122
});
2223

2324
test('a pubspec with a "name" key', () async {

0 commit comments

Comments
 (0)