Improve/increase installation error handling

This commit is contained in:
Lovell Fuller 2018-10-01 11:06:12 +01:00
parent c3274e480b
commit 6007e13a22

View File

@ -18,6 +18,12 @@ const platform = require('../lib/platform');
const minimumLibvipsVersion = libvips.minimumLibvipsVersion; const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`; const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`;
const fail = function (err) {
npmLog.error('sharp', err.message);
npmLog.error('sharp', 'Please see http://sharp.pixelplumbing.com/page/install');
process.exit(1);
};
const extractTarball = function (tarPath) { const extractTarball = function (tarPath) {
const vendorPath = path.join(__dirname, '..', 'vendor'); const vendorPath = path.join(__dirname, '..', 'vendor');
libvips.mkdirSync(vendorPath); libvips.mkdirSync(vendorPath);
@ -27,9 +33,7 @@ const extractTarball = function (tarPath) {
cwd: vendorPath, cwd: vendorPath,
strict: true strict: true
}) })
.catch(function (err) { .catch(fail);
throw err;
});
}; };
try { try {
@ -77,7 +81,9 @@ try {
} }
response.pipe(tmpFile); response.pipe(tmpFile);
}); });
tmpFile.on('close', function () { tmpFile
.on('error', fail)
.on('close', function () {
try { try {
// Attempt to rename // Attempt to rename
fs.renameSync(tarPathTemp, tarPathCache); fs.renameSync(tarPathTemp, tarPathCache);
@ -91,7 +97,5 @@ try {
} }
} }
} catch (err) { } catch (err) {
npmLog.error('sharp', err.message); fail(err);
npmLog.error('sharp', 'Please see http://sharp.pixelplumbing.com/page/install');
process.exit(1);
} }