Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2.1.4 | 2022-06-27

- Automatically retry if VS Code download fails

### 2.1.4 | 2022-06-10

- Fix uncaught error when failing to connect to the extension service
Expand Down
24 changes: 17 additions & 7 deletions lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const extensionRoot = process.cwd();

const vscodeStableReleasesAPI = `https://update.code.visualstudio.com/api/releases/stable`;

const DOWNLOAD_ATTEMPTS = 3;

async function fetchLatestStableVersion(): Promise<string> {
const versions = await request.getJSON(vscodeStableReleasesAPI);
if (!versions || !Array.isArray(versions) || !versions[0]) {
Expand Down Expand Up @@ -228,14 +230,22 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
}
}

try {
const { stream, format } = await downloadVSCodeArchive({ version, platform, cachePath, reporter });
await unzipVSCode(reporter, downloadedPath, extractSync, stream, format);
reporter.report({ stage: ProgressReportStage.NewInstallComplete, downloadedPath })
} catch (err) {
reporter.error(err);
throw Error(`Failed to download and unzip VS Code ${version}`);
for (let i = 0;; i++) {
try {
const { stream, format } = await downloadVSCodeArchive({ version, platform, cachePath, reporter });
await unzipVSCode(reporter, downloadedPath, extractSync, stream, format);
reporter.report({ stage: ProgressReportStage.NewInstallComplete, downloadedPath })
break;
} catch (error) {
if (i++ < DOWNLOAD_ATTEMPTS) {
reporter.report({ stage: ProgressReportStage.Retrying, attempt: i, error: error as Error, totalAttempts: DOWNLOAD_ATTEMPTS });
} else {
reporter.error(error);
throw Error(`Failed to download and unzip VS Code ${version}`);
}
}
}
reporter.report({ stage: ProgressReportStage.NewInstallComplete, downloadedPath })

if (version === 'insiders') {
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath, platform));
Expand Down
24 changes: 15 additions & 9 deletions lib/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum ProgressReportStage {
Downloading = 'downloading',
/** Fired when the command is issued to do a synchronous extraction. May not fire depending on the platform and options. */
ExtractingSynchonrously = 'extractingSynchonrously',
/** Fired when the download fails and a retry will be attempted */
Retrying = 'retrying',
/** Fired after folder is downloaded and unzipped */
NewInstallComplete = 'newInstallComplete',
}
Expand All @@ -33,6 +35,7 @@ export type ProgressReport =
| { stage: ProgressReportStage.FoundMatchingInstall; downloadedPath: string }
| { stage: ProgressReportStage.ResolvingCDNLocation; url: string }
| { stage: ProgressReportStage.Downloading; url: string; totalBytes: number; bytesSoFar: number; }
| { stage: ProgressReportStage.Retrying; error: Error, attempt: number; totalAttempts: number }
| { stage: ProgressReportStage.ExtractingSynchonrously; }
| { stage: ProgressReportStage.NewInstallComplete, downloadedPath: string; }

Expand Down Expand Up @@ -76,9 +79,6 @@ export class ConsoleReporter implements ProgressReporter {
case ProgressReportStage.FoundMatchingInstall:
console.log(`Found existing install in ${report.downloadedPath}. Skipping download`);
break;
case ProgressReportStage.NewInstallComplete:
console.log(`Downloaded VS Code ${this.version} into ${report.downloadedPath}`);
break;
case ProgressReportStage.ResolvingCDNLocation:
console.log(`Downloading VS Code ${this.version} from ${report.url}`)
break;
Expand All @@ -91,13 +91,12 @@ export class ConsoleReporter implements ProgressReporter {
this.downloadReport.report = report;
}
break;
case ProgressReportStage.Retrying:
this.flushDownloadReport();
console.log(`Error downloading, retrying (attempt ${report.attempt} of ${report.totalAttempts}): ${report.error.message}`);
break;
case ProgressReportStage.NewInstallComplete:
if (this.downloadReport) {
clearTimeout(this.downloadReport.timeout);
}
if (this.showDownloadProgress) {
console.log('');
}
this.flushDownloadReport();
console.log(`Downloaded VS Code into ${report.downloadedPath}`);
break;
}
Expand All @@ -107,6 +106,13 @@ export class ConsoleReporter implements ProgressReporter {
console.error(err);
}

private flushDownloadReport() {
if (this.showDownloadProgress) {
this.reportDownload();
console.log('');
}
}

private reportDownload() {
if (!this.downloadReport) {
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/test-electron",
"version": "2.1.4",
"version": "2.1.5",
"scripts": {
"compile": "tsc -p ./",
"watch": "tsc -w -p ./",
Expand Down