Commit 5d40c3e7 authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Improve error messages when bin version requirements are invalid (#457)

parent ac5fb636
......@@ -42,6 +42,9 @@ echo "" > "$LOG_FILE"
handle_failure() {
header "Build failed"
fail_yarn_lockfile_outdated "$LOG_FILE"
fail_node_install "$LOG_FILE"
fail_yarn_install "$LOG_FILE"
fail_invalid_semver "$LOG_FILE"
warn_untracked_dependencies "$LOG_FILE"
warn_angular_resolution "$LOG_FILE"
warn_missing_devdeps "$LOG_FILE"
......
......@@ -15,7 +15,7 @@ install_yarn() {
echo "Resolving yarn version ${version:-(latest)}..."
if ! read number url < <(curl --silent --get --retry 5 --retry-max-time 15 --data-urlencode "range=$version" "https://nodebin.herokai.com/v1/yarn/$platform/latest.txt"); then
echo "Unable to resolve; does that version exist?" && false
fail_bin_install yarn $version;
fi
echo "Downloading and installing yarn ($number)..."
......@@ -41,7 +41,7 @@ install_nodejs() {
echo "Resolving node version $version..."
if ! read number url < <(curl --silent --get --retry 5 --retry-max-time 15 --data-urlencode "range=$version" "https://nodebin.herokai.com/v1/node/$platform/latest.txt"); then
echo "Unable to resolve; does that version exist?" && false
fail_bin_install node $version;
fi
echo "Downloading and installing node $number..."
......@@ -61,7 +61,7 @@ install_iojs() {
echo "Resolving iojs version ${version:-(latest stable)}..."
if ! read number url < <(curl --silent --get --retry 5 --retry-max-time 15 --data-urlencode "range=$version" "https://nodebin.herokai.com/v1/iojs/$platform/latest.txt"); then
echo "Unable to resolve; does that version exist?" && false
fail_bin_install iojs $version;
fi
echo "Downloading and installing iojs $number..."
......
......@@ -123,7 +123,7 @@ fail_yarn_lockfile_outdated() {
echo ""
warn "Outdated Yarn lockfile
Your application contains a Yarn lockfile (yarn.lock) which does not
Your application contains a Yarn lockfile (yarn.lock) which does not
match the dependencies in package.json. This can happen if you use npm
to install or update a dependency instead of Yarn.
......@@ -139,6 +139,112 @@ fail_yarn_lockfile_outdated() {
fi
}
fail_bin_install() {
local bin="$1"
local version="$2"
# re-curl the result, saving off the reason for the failure this time
local error=$(curl --silent --get --retry 5 --retry-max-time 15 --data-urlencode "range=$version" "https://nodebin.herokai.com/v1/$bin/$platform/latest.txt")
if [[ $error = "No result" ]]; then
case $bin in
node)
echo "Could not find Node version corresponding to version requirement: $version";;
iojs)
echo "Could not find Iojs version corresponding to version requirement: $version";;
yarn)
echo "Could not find Yarn version corresponding to version requirement: $version";;
esac
else
echo "Error: Invalid semantic version \"$version\""
fi
false
}
fail_node_install() {
local log_file="$1"
local node_engine=$(read_json "$BUILD_DIR/package.json" ".engines.node")
if grep -qi 'Could not find Node version corresponding to version requirement' "$log_file"; then
mcount "failures.invalid-node-version"
echo ""
warn "No matching version found for Node: $node_engine
Heroku supports the latest Stable version of Node.js as well as all
active LTS (Long-Term-Support) versions, however you have specified
a version in package.json ($node_engine) that does not correspond to
any published version of Node.js.
You should always specify a Node.js version that matches the runtime
you’re developing and testing with. To find your version locally:
$ node --version
v6.11.1
Use the engines section of your package.json to specify the version of
Node.js to use on Heroku. Drop the ‘v’ to save only the version number:
\"engines\": {
\"node\": \"6.11.1\"
}
" https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-no-matching-node-versions
exit 1
fi
}
fail_yarn_install() {
local log_file="$1"
local yarn_engine=$(read_json "$BUILD_DIR/package.json" ".engines.yarn")
if grep -qi 'Could not find Yarn version corresponding to version requirement' "$log_file"; then
mcount "failures.invalid-yarn-version"
echo ""
warn "No matching version found for Yarn: $yarn_engine
Heroku supports every version of Yarn published on npm, however you have
specified a version in package.json ($yarn_engine) that does not correspond
to any published version of Yarn. You can see a list of all published
versions of Yarn with the following command:
$ yarn info yarn versions
You should always specify a Yarn version that matches the version
you’re developing and testing with. To find your version locally:
$ yarn --version
0.27.5
Use the engines section of your package.json to specify the version of
Yarn to use on Heroku.
\"engines\": {
\"yarn\": \"0.27.5\"
}
" https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-no-matching-yarn-versions
exit 1
fi
}
fail_invalid_semver() {
local log_file="$1"
if grep -qi 'Error: Invalid semantic version' "$log_file"; then
mcount "failures.invalid-semver-requirement"
echo ""
warn "Invalid semver requirement
Node, Yarn, and npm adhere to semver, the semantic versioning convention
popularized by GitHub.
http://semver.org/
However you have specified a version requirement that is not a valid
semantic version.
" https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-an-invalid-semver-requirement
exit 1
fi
}
warning() {
local tip=${1:-}
local url=${2:-https://devcenter.heroku.com/articles/nodejs-support}
......
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"dependencies": {
},
"engines": {
"node": "stable"
}
}
{
"name": "yarn",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"engines": {
"yarn": "0.17q"
},
"dependencies": {
"lodash": "^4.16.4"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
lodash:
version "4.16.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.16.4.tgz#01ce306b9bad1319f2a5528674f88297aeb70127"
{
"name": "yarn",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"engines": {
"yarn": "0.171"
},
"dependencies": {
"lodash": "^4.16.4"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
lodash:
version "4.16.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.16.4.tgz#01ce306b9bad1319f2a5528674f88297aeb70127"
......@@ -89,6 +89,24 @@ testYarnSemver() {
assertCapturedSuccess
}
testYarnInvalid() {
compile "yarn-invalid"
assertCaptured "Resolving yarn version 0.171"
assertCaptured "Could not find Yarn version corresponding to version requirement: 0.171"
assertCaptured "No matching version found for Yarn: 0.171"
assertCaptured "https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-no-matching-yarn-versions"
assertCapturedError
}
testYarnSemverInvalid() {
compile "yarn-invalid-semver"
assertCaptured "Resolving yarn version 0.17q"
assertCaptured "Error: Invalid semantic version \"0.17q\""
assertCaptured "Invalid semver requirement"
assertCaptured "https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-an-invalid-semver-requirement"
assertCapturedError
}
testYarnRun() {
compile "yarn-run"
assertCaptured "Running heroku-postbuild (yarn)"
......@@ -345,14 +363,24 @@ testConcurrencyCustomLimit() {
testInvalidNode() {
compile "invalid-node"
assertCaptured "Resolving node version 0.11.333"
assertCaptured "Unable to resolve"
assertCaptured "Could not find Node version corresponding to version requirement: 0.11.333"
assertCaptured "No matching version found for Node: 0.11.333"
assertCaptured "https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-no-matching-node-versions"
assertCapturedError
}
testInvalidNodeSemver() {
compile "invalid-node-semver"
assertCaptured "Resolving node version stable"
assertCaptured "Error: Invalid semantic version \"stable\""
assertCaptured "Invalid semver requirement"
assertCapturedError
}
testInvalidIo() {
compile "invalid-io"
assertCaptured "Resolving iojs version 2.0.99"
assertCaptured "Unable to resolve"
assertCaptured "Could not find Iojs version corresponding to version requirement: 2.0.99"
assertCapturedError
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment