diff --git a/bin/pub.dart b/bin/pub.dart index 35b8c90ef63e1d6a326d49c14ea34cd61e71c93b..8f7fa4e32ddb192e82476c190c4953617b49973d 100644 --- a/bin/pub.dart +++ b/bin/pub.dart @@ -17,6 +17,7 @@ import '../lib/src/http.dart'; import '../lib/src/io.dart'; import '../lib/src/log.dart' as log; import '../lib/src/sdk.dart' as sdk; +import '../lib/src/solver/version_solver.dart'; import '../lib/src/utils.dart'; void main(List<String> arguments) { @@ -115,7 +116,8 @@ int chooseExitCode(exception) { while (exception is WrappedException) exception = exception.innerError; if (exception is HttpException || exception is http.ClientException || - exception is SocketException || exception is PubHttpException) { + exception is SocketException || exception is PubHttpException || + exception is DependencyNotFoundException) { return exit_codes.UNAVAILABLE; } else if (exception is FormatException || exception is DataException) { return exit_codes.DATA; diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index 57f806a14af74b18b587438eab3041b827c7fc01..d762507354f30642062949cdae9e8ac54893b8e6 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart @@ -110,7 +110,13 @@ class GlobalPackages { // Resolve it and download its dependencies. return resolveVersions(SolveType.GET, cache.sources, root).then((result) { - if (!result.succeeded) throw result.error; + if (!result.succeeded) { + // If the package specified by the user doesn't exist, we want to + // surface that as a [DataError] with the associated exit code. + if (result.error.package != dep.name) throw result.error; + if (result.error is NoVersionException) dataError(result.error.message); + throw result.error; + } result.showReport(SolveType.GET); // Make sure all of the dependencies are locally installed. diff --git a/lib/src/solver/backtracking_solver.dart b/lib/src/solver/backtracking_solver.dart index d8cc66ad53e2b255aab1592bed3f618eba89db37..cf12722fcb92ab15a12bfacd77ab8300265533e8 100644 --- a/lib/src/solver/backtracking_solver.dart +++ b/lib/src/solver/backtracking_solver.dart @@ -700,7 +700,8 @@ class Traverser { var pubDep = override == null ? new PackageDep(depName, "hosted", constraint, depName) : override.withConstraint(constraint); - return _registerDependency(new Dependency("pub itself", null, pubDep)); + return _registerDependency( + new Dependency("pub itself", Version.none, pubDep)); })); } diff --git a/lib/src/solver/version_solver.dart b/lib/src/solver/version_solver.dart index 471f09536e2046b123870421793fdda69e2917d2..e2af2d41686b38bf536ce8fd2bb8f8792e164fa0 100644 --- a/lib/src/solver/version_solver.dart +++ b/lib/src/solver/version_solver.dart @@ -280,13 +280,16 @@ class Dependency { final String depender; /// The version of the depender that has this dependency. - /// - /// This will be `null` when [depender] is the magic "pub itself" dependency. final Version dependerVersion; /// The package being depended on. final PackageDep dep; + /// Whether [depender] is a magic dependency (e.g. "pub itself" or "pub global + /// activate"). + bool get isMagic => depender.contains(" "); + + Dependency(this.depender, this.dependerVersion, this.dep); String toString() => '$depender $dependerVersion -> $dep'; @@ -347,9 +350,7 @@ abstract class SolveFailure implements ApplicationException { for (var dep in sorted) { buffer.writeln(); buffer.write("- ${log.bold(dep.depender)}"); - if (dep.dependerVersion != null) { - buffer.write(" ${dep.dependerVersion}"); - } + if (!dep.isMagic) buffer.write(" ${dep.dependerVersion}"); buffer.write(" ${_describeDependency(dep.dep)}"); } diff --git a/test/get/hosted/get_test.dart b/test/get/hosted/get_test.dart index 2779da1a1740a66dc02650b172a148e604b5dee0..fa2ffe43ad76b1f922d46c300fc1a6270bd0ce7d 100644 --- a/test/get/hosted/get_test.dart +++ b/test/get/hosted/get_test.dart @@ -4,6 +4,7 @@ library pub_tests; +import '../../../lib/src/exit_codes.dart' as exit_codes; import '../../descriptor.dart' as d; import '../../test_pub.dart'; @@ -25,7 +26,9 @@ main() { d.appDir({"bad name!": "1.2.3"}).create(); - pubGet(error: new RegExp( - r"Could not find package bad name! at http://localhost:\d+\.")); + pubGet( + error: new RegExp( + r"Could not find package bad name! at http://localhost:\d+\."), + exitCode: exit_codes.UNAVAILABLE); }); } diff --git a/test/get/path/nonexistent_dir_test.dart b/test/get/path/nonexistent_dir_test.dart index 95698fc59a12a5a291bf2bcc0700e0ee9b70b7f4..6a983c4cca3d4566d1dfbfdb62aa55614332f605 100644 --- a/test/get/path/nonexistent_dir_test.dart +++ b/test/get/path/nonexistent_dir_test.dart @@ -4,6 +4,7 @@ import 'package:path/path.dart' as path; +import '../../../lib/src/exit_codes.dart' as exit_codes; import '../../descriptor.dart' as d; import '../../test_pub.dart'; @@ -18,8 +19,10 @@ main() { }) ]).create(); - pubGet(error: """Could not find package foo at "$badPath". -Depended on by: -- myapp 0.0.0"""); + pubGet(error: """ + Could not find package foo at "$badPath". + Depended on by: + - myapp 0.0.0""", + exitCode: exit_codes.UNAVAILABLE); }); } \ No newline at end of file diff --git a/test/global/activate/activate_git_after_hosted_test.dart b/test/global/activate/activate_git_after_hosted_test.dart index a553f5f4bb34b5f374ef03e4718f1a0454be68e3..9aea6fdb7c99b4d485d135854dc2cf106f4af45f 100644 --- a/test/global/activate/activate_git_after_hosted_test.dart +++ b/test/global/activate/activate_git_after_hosted_test.dart @@ -31,6 +31,7 @@ main() { output: """ Package foo is currently active at version 1.0.0. Resolving dependencies... + + foo 1.0.0 from git ../foo.git Activated foo 1.0.0 from Git repository "../foo.git"."""); // Should now run the git one. diff --git a/test/global/activate/activate_hosted_after_git_test.dart b/test/global/activate/activate_hosted_after_git_test.dart index 9afb49fd78b22cfa5a3b95d99b14e2f9868daea3..296490ffa5b6169b2082b5dcef7a949768a34029 100644 --- a/test/global/activate/activate_hosted_after_git_test.dart +++ b/test/global/activate/activate_hosted_after_git_test.dart @@ -31,8 +31,9 @@ main() { var path = canonicalize(p.join(sandboxDir, "foo")); schedulePub(args: ["global", "activate", "foo"], output: """ Package foo is currently active from Git repository "../foo.git". - Downloading foo 2.0.0... Resolving dependencies... + + foo 2.0.0 + Downloading foo 2.0.0... Activated foo 2.0.0."""); // Should now run the hosted one. diff --git a/test/global/activate/activate_hosted_after_path_test.dart b/test/global/activate/activate_hosted_after_path_test.dart index 6dec06bdceb5dfd636b4f1cc5f213ea873742562..6cd26d00128ace56f9102337348ee7b96a677359 100644 --- a/test/global/activate/activate_hosted_after_path_test.dart +++ b/test/global/activate/activate_hosted_after_path_test.dart @@ -31,8 +31,9 @@ main() { var path = canonicalize(p.join(sandboxDir, "foo")); schedulePub(args: ["global", "activate", "foo"], output: """ Package foo is currently active at path "$path". - Downloading foo 2.0.0... Resolving dependencies... + + foo 2.0.0 + Downloading foo 2.0.0... Activated foo 2.0.0."""); // Should now run the hosted one. diff --git a/test/global/activate/cached_package_test.dart b/test/global/activate/cached_package_test.dart index 8865883b82b6788cccdf811b89bdb91090890600..c9071c750dfeb82d41ebcbbab4252c12a18065f2 100644 --- a/test/global/activate/cached_package_test.dart +++ b/test/global/activate/cached_package_test.dart @@ -17,8 +17,9 @@ main() { schedulePub(args: ["cache", "add", "foo"]); schedulePub(args: ["global", "activate", "foo"], output: """ -Resolving dependencies... -Activated foo 1.0.0."""); + Resolving dependencies... + + foo 1.0.0 + Activated foo 1.0.0."""); // Should be in global package cache. d.dir(cachePath, [ diff --git a/test/global/activate/different_version_test.dart b/test/global/activate/different_version_test.dart index 57fa511ca26a81bbfdecf488ede1ec29f6984af1..d9542f732031517e791ffecd2c9f552e58077f05 100644 --- a/test/global/activate/different_version_test.dart +++ b/test/global/activate/different_version_test.dart @@ -18,9 +18,10 @@ main() { // Activating it again with a different constraint changes the version. schedulePub(args: ["global", "activate", "foo", ">1.0.0"], output: """ -Package foo is currently active at version 1.0.0. -Downloading foo 2.0.0... -Resolving dependencies... -Activated foo 2.0.0."""); + Package foo is currently active at version 1.0.0. + Resolving dependencies... + + foo 2.0.0 + Downloading foo 2.0.0... + Activated foo 2.0.0."""); }); } diff --git a/test/global/activate/empty_constraint_test.dart b/test/global/activate/empty_constraint_test.dart index 6b8b7fbb2459b4a7a571afc1bf0f4e2f82471880..4d29194d6e67299cbfe5e989c2cc9e528096cee1 100644 --- a/test/global/activate/empty_constraint_test.dart +++ b/test/global/activate/empty_constraint_test.dart @@ -14,7 +14,9 @@ main() { ]); schedulePub(args: ["global", "activate", "foo", ">1.1.0"], - error: "Package foo has no versions that match >1.1.0.", + error: """ + Package foo has no versions that match >1.1.0 derived from: + - pub global activate depends on version >1.1.0""", exitCode: exit_codes.DATA); }); } diff --git a/test/global/activate/git_package_test.dart b/test/global/activate/git_package_test.dart index 4426c74c754de45697653e149d027004b14819db..eea65e8e411eec71979ca9e5402d4c447ce2d07b 100644 --- a/test/global/activate/git_package_test.dart +++ b/test/global/activate/git_package_test.dart @@ -19,7 +19,8 @@ main() { schedulePub(args: ["global", "activate", "-sgit", "../foo.git"], output: ''' -Resolving dependencies... -Activated foo 1.0.0 from Git repository "../foo.git".'''); + Resolving dependencies... + + foo 1.0.0 from git ../foo.git + Activated foo 1.0.0 from Git repository "../foo.git".'''); }); } diff --git a/test/global/activate/ignores_active_version_test.dart b/test/global/activate/ignores_active_version_test.dart index 36508558add05dc1db99f9299355c5ef088e432c..e578b81db72fe247c2e9b8ebb660b61e08de5407 100644 --- a/test/global/activate/ignores_active_version_test.dart +++ b/test/global/activate/ignores_active_version_test.dart @@ -18,9 +18,10 @@ main() { // Activating it again resolves to the new best version. schedulePub(args: ["global", "activate", "foo", ">1.0.0"], output: """ -Package foo is currently active at version 1.2.3. -Downloading foo 1.3.0... -Resolving dependencies... -Activated foo 1.3.0."""); + Package foo is currently active at version 1.2.3. + Resolving dependencies... + + foo 1.3.0 + Downloading foo 1.3.0... + Activated foo 1.3.0."""); }); } diff --git a/test/global/activate/reactivating_git_upgrades_test.dart b/test/global/activate/reactivating_git_upgrades_test.dart index 6a25d23fe898464a28b104b7a634e3d092104785..a07d667ec059bd56b2dc447032a9b513bdcdeb94 100644 --- a/test/global/activate/reactivating_git_upgrades_test.dart +++ b/test/global/activate/reactivating_git_upgrades_test.dart @@ -17,8 +17,9 @@ main() { schedulePub(args: ["global", "activate", "-sgit", "../foo.git"], output: ''' -Resolving dependencies... -Activated foo 1.0.0 from Git repository "../foo.git".'''); + Resolving dependencies... + + foo 1.0.0 from git ../foo.git + Activated foo 1.0.0 from Git repository "../foo.git".'''); d.git('foo.git', [ d.libPubspec("foo", "1.0.1") @@ -27,8 +28,9 @@ Activated foo 1.0.0 from Git repository "../foo.git".'''); // Activating it again pulls down the latest commit. schedulePub(args: ["global", "activate", "-sgit", "../foo.git"], output: ''' -Package foo is currently active from Git repository "../foo.git". -Resolving dependencies... -Activated foo 1.0.1 from Git repository "../foo.git".'''); + Package foo is currently active from Git repository "../foo.git". + Resolving dependencies... + + foo 1.0.1 from git ../foo.git + Activated foo 1.0.1 from Git repository "../foo.git".'''); }); } diff --git a/test/global/activate/uncached_package_test.dart b/test/global/activate/uncached_package_test.dart index a134ab6faeb1d2472445b521931adaf58b28cc20..9f9041db9ad74722175f05821bafb8cece6ff6c5 100644 --- a/test/global/activate/uncached_package_test.dart +++ b/test/global/activate/uncached_package_test.dart @@ -17,10 +17,10 @@ main() { ]); schedulePub(args: ["global", "activate", "foo"], output: """ -Downloading foo 1.2.3... -Resolving dependencies... -Activated foo 1.2.3. - """); + Resolving dependencies... + + foo 1.2.3 (2.0.0-wildly.unstable available) + Downloading foo 1.2.3... + Activated foo 1.2.3."""); // Should be in global package cache. d.dir(cachePath, [ diff --git a/test/global/deactivate/deactivate_and_reactivate_package_test.dart b/test/global/deactivate/deactivate_and_reactivate_package_test.dart index b1c6005d37cb97f6ad7a36e7674fa3fc05c58531..17f02407145fad7c1909609fabaf9967a2fd4519 100644 --- a/test/global/deactivate/deactivate_and_reactivate_package_test.dart +++ b/test/global/deactivate/deactivate_and_reactivate_package_test.dart @@ -20,9 +20,9 @@ main() { // Activating again should forget the old version. schedulePub(args: ["global", "activate", "foo"], output: """ -Downloading foo 2.0.0... -Resolving dependencies... -Activated foo 2.0.0. - """); + Resolving dependencies... + + foo 2.0.0 + Downloading foo 2.0.0... + Activated foo 2.0.0."""); }); } diff --git a/test/hosted/fail_gracefully_on_missing_package_test.dart b/test/hosted/fail_gracefully_on_missing_package_test.dart index 527f597ab5c5584c9d0d48d3dceb125a8a50318b..60be82ffbe132f27a1ecb3b1c531974b39d6933a 100644 --- a/test/hosted/fail_gracefully_on_missing_package_test.dart +++ b/test/hosted/fail_gracefully_on_missing_package_test.dart @@ -4,8 +4,10 @@ library pub_tests; +import '../../lib/src/exit_codes.dart' as exit_codes; import '../descriptor.dart' as d; import '../test_pub.dart'; +import '../test_pub.dart'; main() { initConfig(); @@ -19,7 +21,8 @@ main() { pubCommand(command, error: new RegExp(r""" Could not find package foo at http://localhost:\d+\. Depended on by: -- myapp""", multiLine: true)); +- myapp""", multiLine: true), + exitCode: exit_codes.UNAVAILABLE); }); }); }