@@ -35,27 +35,26 @@ function download(destinationPath, url, callback)
3535 requestWithRedirects(url, 10,
3636 function(error) {
3737 var url = host + '/' + path;
38− throw new Error('Error fetching binary from ' + url + ': ' + error);
38+ exitFailure(url, 'Error fetching binary from ' + url + ': ' + error);
3939 },
4040 function(response) {
4141 if (response.statusCode == 404)
4242 {
43− // TODO give specific error message
44− throw new Error('Not Found: ' + url);
43+ exitFailure(url, 'I got a "404 Not Found" trying to download from the following URL:\n' + url);
4544 }
4645
4746 response.on('error', function() {
48− throw new Error('Error receiving ' + url);
47+ exitFailure(url, 'Something went wrong while receiving the following URL:\n\n' + url);
4948 });
5049
5150 var gunzip = zlib.createGunzip().on('error', function(error) {
52− throw new Error('Error decompressing elm.gz: ' + error);
51+ exitFailure(url, 'I ran into trouble decompressing the downloaded binary. It is saying:\n\n' + error);
5352 });
5453 var write = fs.createWriteStream(destinationPath, {
5554 encoding: 'binary',
5655 mode: 0o755
5756 }).on('finish', callback).on('error', function(error) {
58− throw new Error('Error writing file: ' + error);
57+ exitFailure(url, 'I had some trouble writing file to disk. It is saying:\n\n' + error);
5958 });
6059
6160 response.pipe(gunzip).pipe(write);
@@ -93,3 +92,20 @@ function requestWithRedirects(url, maxRedirects, failure, success)
9392
9493 req.end();
9594}
95+
96+
97+
98+// EXIT FAILURE
99+
100+
101+function exitFailure(url, message)
102+{
103+ console.error(
104+ '-- ERROR -----------------------------------------------------------------------\n\n'
105+ + message
106+ + '\n\nNOTE: You can avoid npm entirely by downloading directly from:\n'
107+ + url + '\nAll this package does is download that file and put it somewhere.\n\n'
108+ + '--------------------------------------------------------------------------------\n'
109+ );
110+ process.exit(1);
111+}