diff --git a/lib/check-started.js b/lib/check-started.js index d4a9d2d2..1052535a 100644 --- a/lib/check-started.js +++ b/lib/check-started.js @@ -12,7 +12,7 @@ async function checkStarted(seleniumArgs) { retry: 0, }; - let attempts = 10; + let attempts = 20; const startTime = Date.now(); while (attempts > 0 && Date.now() - startTime < 60000) { await sleep(500); diff --git a/lib/install-utils.js b/lib/install-utils.js index 2afe7bab..a306c0a9 100644 --- a/lib/install-utils.js +++ b/lib/install-utils.js @@ -9,6 +9,7 @@ const fs = require('fs'); const got = require('got'); const merge = require('lodash.merge'); const debug = require('debug')('selenium-standalone:install'); +const { logError } = require('./log-error'); const installers = ['selenium', 'chrome', 'ie', 'firefox', 'edge', 'chromiumedge']; @@ -58,7 +59,7 @@ const chmod = (where) => debug('chmod 0755 on', where); fs.chmod(where, '0755', (err) => { if (err) { - return reject(err); + return reject(logError('chmod', err)); } resolve(); }); @@ -117,7 +118,9 @@ function isUpToDate(url, requestOpts, hash, cb) { cb(false); }) .catch((err) => { - return cb(new Error(`Could not request headers from ${url}: ${err.response.statusCode}`)); + return cb( + new Error(`Could not request headers from ${url}: ${err.response ? err.response.statusCode : err.message}`) + ); }); } @@ -131,7 +134,7 @@ async function uncompressDownloadedFile(zipFilePath) { return new Promise((resolve, reject) => yauzl.open(zipFilePath, function onOpenZipFile(err, zipFile) { if (err) { - return reject(err); + return reject(logError('uncompressDownloadedFile:yauzl.open', err)); } zipFile.on('entry', (entry) => { if (/.*\/.*/.test(entry.fileName)) { @@ -139,14 +142,18 @@ async function uncompressDownloadedFile(zipFilePath) { } zipFile.openReadStream(entry, { autoClose: true }, function onOpenZipFileEntryReadStream(errRead, readStream) { if (errRead) { - return reject(errRead); + return reject(logError('uncompressDownloadedFile:zipFile.openReadStream', err)); } const extractPath = path.join( path.dirname(zipFilePath), isBrowserDriver(entry.fileName) ? path.basename(zipFilePath, '.zip') : entry.fileName ); - const extractWriteStream = fs.createWriteStream(extractPath).once('error', reject); - readStream.pipe(extractWriteStream).once('error', reject); + const extractWriteStream = fs + .createWriteStream(extractPath) + .once('error', (errWs) => reject(logError('uncompressDownloadedFile:readStream.pipe', errWs))); + readStream + .pipe(extractWriteStream) + .once('error', (errPipe) => reject(logError('uncompressDownloadedFile:readStream.pipe', errPipe))); }); }); zipFile.on('close', resolve); @@ -157,7 +164,9 @@ async function uncompressDownloadedFile(zipFilePath) { async function uncompressGzippedFile(from, gzipFilePath) { return new Promise((resolve, reject) => { const extractPath = path.join(path.dirname(gzipFilePath), path.basename(gzipFilePath, '.gz')); - const writeStream = fs.createWriteStream(extractPath).once('error', reject); + const writeStream = fs + .createWriteStream(extractPath) + .once('error', (err) => reject(logError('uncompressGzippedFile:createWriteStream', err))); const gunzippedContent = fs.createReadStream(gzipFilePath).pipe(gunzip).once('error', reject); if (from.substr(-7) === '.tar.gz') { @@ -210,7 +219,7 @@ async function runInstaller(installerFile, from, to) { runner.on('exit', () => { fs.readFile(logFile, 'utf16le', (err, data) => { if (err) { - return reject(err); + return reject(logError('runInstaller:readFile', err)); } const installDir = data @@ -230,11 +239,11 @@ async function runInstaller(installerFile, from, to) { }) .pipe(fs.createWriteStream(to, { autoClose: true })) .once('finish', resolve) - .once('error', reject); + .once('error', (errWs) => reject(logError('runInstaller:createWriteStream', errWs))); }); }); - runner.on('error', reject); + runner.on('error', (errRunner) => reject(logError('runInstaller:runner', errRunner))); }); } diff --git a/lib/install.js b/lib/install.js index 780fa7b7..ded8eef2 100644 --- a/lib/install.js +++ b/lib/install.js @@ -24,6 +24,7 @@ const { runInstaller, } = require('./install-utils'); const { checkArgs } = require('./check-args'); +const { logError } = require('./log-error'); /** * used ONLY to deal with progress bar. @@ -69,7 +70,7 @@ async function install(_opts, _cb) { delete opts.drivers.chromiumedge; } - const requestOpts = Object.assign({ timeout: 60000 }, opts.requestOpts); + const requestOpts = Object.assign({ timeout: 90000 }, opts.requestOpts); if (opts.proxy) { requestOpts.proxy = opts.proxy; } @@ -204,7 +205,10 @@ async function install(_opts, _cb) { const stream = await getDownloadStream(from); return new Promise((resolve, reject) => - stream.pipe(fs.createWriteStream(to)).once('error', reject).once('finish', resolve) + stream + .pipe(fs.createWriteStream(to)) + .once('error', (err) => reject(logError('installSingleFile', err))) + .once('finish', resolve) ); } @@ -217,7 +221,9 @@ async function install(_opts, _cb) { const installerFile = getTempFileName('installer.msi'); await new Promise((resolve, reject) => { - const msiWriteStream = fs.createWriteStream(installerFile).once('error', reject); + const msiWriteStream = fs + .createWriteStream(installerFile) + .once('error', (err) => reject(logError('downloadInstallerFile', err))); stream.pipe(msiWriteStream); msiWriteStream.once('finish', resolve); @@ -251,7 +257,9 @@ async function install(_opts, _cb) { // Store downloaded compressed file await new Promise((resolve, reject) => { - const gzipWriteStream = fs.createWriteStream(to).once('error', reject); + const gzipWriteStream = fs + .createWriteStream(to) + .once('error', (err) => reject(logError('installGzippedFile', err))); stream.pipe(gzipWriteStream); gzipWriteStream.once('finish', resolve); @@ -265,7 +273,9 @@ async function install(_opts, _cb) { await new Promise((resolve, reject) => { // Store downloaded compressed file - const zipWriteStream = fs.createWriteStream(to).once('error', reject); + const zipWriteStream = fs + .createWriteStream(to) + .once('error', (err) => reject(logError('installZippedFile', err))); stream.pipe(zipWriteStream); // Uncompress downloaded file @@ -298,10 +308,7 @@ async function install(_opts, _cb) { .once('end', () => { downloadStreams.delete(downloadStream); }) - .once('error', (err) => { - console.error(err); - reject(new Error('Could not download ' + downloadUrl)); - }); + .once('error', (err) => reject(logError('getDownloadStream', err, 'Could not download ' + downloadUrl))); }); } } diff --git a/lib/log-error.js b/lib/log-error.js new file mode 100644 index 00000000..eb17de0b --- /dev/null +++ b/lib/log-error.js @@ -0,0 +1,14 @@ +const logError = (fnName, error, message = '') => { + console.error(`Error in "${fnName}". ${message}\nSee more details below:`); + if (error) { + if (error.response) { + console.log(error.response.statusCode, error.response.url); + } + console.error(error.message || error); + } + return error; +}; + +module.exports = { + logError, +};