Fail gracefully when chromium failed to download (#430)
Fail gracefully when chromium failed to download This patch changes both install.js and Launcher.js to inform how chromium could be downloaded manually.
This commit is contained in:
parent
598f439a32
commit
c1731dd5d7
16
install.js
16
install.js
@ -15,18 +15,28 @@
|
||||
*/
|
||||
|
||||
const Downloader = require('./utils/ChromiumDownloader');
|
||||
const platform = Downloader.currentPlatform();
|
||||
const revision = require('./package').puppeteer.chromium_revision;
|
||||
const ProgressBar = require('progress');
|
||||
|
||||
const revisionInfo = Downloader.revisionInfo(platform, revision);
|
||||
// Do nothing if the revision is already downloaded.
|
||||
if (Downloader.revisionInfo(Downloader.currentPlatform(), revision))
|
||||
if (revisionInfo.downloaded)
|
||||
return;
|
||||
|
||||
let allRevisions = Downloader.downloadedRevisions();
|
||||
Downloader.downloadRevision(Downloader.currentPlatform(), revision, onProgress)
|
||||
Downloader.downloadRevision(platform, revision, onProgress)
|
||||
// Remove previous chromium revisions.
|
||||
.then(() => Promise.all(allRevisions.map(({platform, revision}) => Downloader.removeRevision(platform, revision))))
|
||||
.catch(error => console.error('Download failed: ' + error.message));
|
||||
.catch(onError);
|
||||
|
||||
function onError(error) {
|
||||
console.error(`ERROR: Failed to download chromium r${revision}!
|
||||
- Download chromium manually:
|
||||
${revisionInfo.url}
|
||||
- Extract chromium into ${revisionInfo.folderPath}
|
||||
* Chromium executable should be at ${revisionInfo.executablePath}`);
|
||||
}
|
||||
|
||||
let progressBar = null;
|
||||
function onProgress(bytesTotal, delta) {
|
||||
|
@ -72,7 +72,7 @@ class Launcher {
|
||||
if (typeof chromeExecutable !== 'string') {
|
||||
let chromiumRevision = require('../package.json').puppeteer.chromium_revision;
|
||||
let revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), chromiumRevision);
|
||||
console.assert(revisionInfo, 'Chromium revision is not downloaded. Run npm install');
|
||||
console.assert(revisionInfo.downloaded, `Chromium revision is not downloaded. Run "npm install"`);
|
||||
chromeExecutable = revisionInfo.executablePath;
|
||||
}
|
||||
if (Array.isArray(options.args))
|
||||
|
@ -59,7 +59,7 @@ else
|
||||
const Downloader = require('../utils/ChromiumDownloader');
|
||||
const chromiumRevision = require('../package.json').puppeteer.chromium_revision;
|
||||
const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), chromiumRevision);
|
||||
console.assert(revisionInfo, `Chromium r${chromiumRevision} is not downloaded. Run 'npm install' and try to re-run tests.`);
|
||||
console.assert(revisionInfo.downloaded, `Chromium r${chromiumRevision} is not downloaded. Run 'npm install' and try to re-run tests.`);
|
||||
}
|
||||
|
||||
let server;
|
||||
|
@ -129,13 +129,11 @@ module.exports = {
|
||||
/**
|
||||
* @param {string} platform
|
||||
* @param {string} revision
|
||||
* @return {?{executablePath: string}}
|
||||
* @return {!{folderPath: string, executablePath: string, downloaded: boolean, url: string}}
|
||||
*/
|
||||
revisionInfo: function(platform, revision) {
|
||||
console.assert(downloadURLs[platform], `Unsupported platform: ${platform}`);
|
||||
let folderPath = getFolderPath(platform, revision);
|
||||
if (!fs.existsSync(folderPath))
|
||||
return null;
|
||||
let executablePath = '';
|
||||
if (platform === 'mac')
|
||||
executablePath = path.join(folderPath, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
|
||||
@ -146,7 +144,10 @@ module.exports = {
|
||||
else
|
||||
throw 'Unsupported platfrom: ' + platfrom;
|
||||
return {
|
||||
executablePath: executablePath
|
||||
executablePath,
|
||||
folderPath,
|
||||
downloaded: fs.existsSync(folderPath),
|
||||
url: util.format(downloadURLs[platform], revision)
|
||||
};
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user