diff --git a/tools/commands-packages.js b/tools/commands-packages.js index b2caa483bd..954433b21d 100644 --- a/tools/commands-packages.js +++ b/tools/commands-packages.js @@ -2094,15 +2094,22 @@ main.registerCommand({ } _.each(constraints, function (constraint) { + var thisConstraintFailed = false; + // Check that the package exists. doOrDie({title: 'Checking package: ' + constraint.name }, function () { if (! catalog.complete.getPackage(constraint.name)) { Console.error(constraint.name + ": no such package"); - failed = true; + thisConstraintFailed = true; return; } }); + if (thisConstraintFailed) { + failed = true; + return; + } + // If the version was specified, check that the version exists. _.each(constraint.constraints, function (constr) { if (constr.version !== null) { @@ -2112,11 +2119,17 @@ main.registerCommand({ if (! versionInfo) { Console.stderr.write( constraint.name + "@" + constr.version + ": no such version\n"); - failed = true; + thisConstraintFailed = true; return; } } }); + + if (thisConstraintFailed) { + failed = true; + return; + } + // Check that the constraint is new. If we are already using the package at // the same constraint in the app, return from this function, but don't // fail. Rejecting the entire command because a part of it is a no-op is diff --git a/tools/tests/package-tests.js b/tools/tests/package-tests.js index b4f4bb4342..121c4a4571 100644 --- a/tools/tests/package-tests.js +++ b/tools/tests/package-tests.js @@ -285,6 +285,13 @@ selftest.define("add packages to app", ["net"], function () { run.matchErr("no such version"); run.expectExit(1); + // Adding a nonexistent package at a nonexistent version should print + // only one error message, not two. (We used to print "no such + // package" and "no such version".) + run = s.run("add", "not-a-real-package-and-never-will-be@1.0.0"); + run.matchErr("no such package"); + run.expectExit(1); + run.forbidAll("no such version"); run = s.run("add", "accounts-base"); @@ -294,6 +301,15 @@ selftest.define("add packages to app", ["net"], function () { checkPackages(s, ["meteor-platform", "accounts-base"]); + // Adding the nonexistent version now should still say "no such + // version". Regression test for + // https://github.com/meteor/meteor/issues/2898. + run = s.run("add", "accounts-base@0.123.123"); + run.matchErr("no such version"); + run.expectExit(1); + run.forbidAll("Currently using accounts-base"); + run.forbidAll("will be changed to"); + run = s.run("--once"); run = s.run("add", "say-something@1.0.0");