Skip to content

Commit 3079fb5

Browse files
authored
ignore update failures caused by no network present (microsoft#2808)
1 parent 9f1b482 commit 3079fb5

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

Extension/src/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,10 @@ export function downloadFileToDestination(urlStr: string, destinationPath: strin
630630
// Write file using downloaded data
631631
let createdFile: fs.WriteStream = fs.createWriteStream(destinationPath);
632632
createdFile.on('finish', () => { resolve(); });
633-
response.on('error', (error) => { reject(); });
633+
response.on('error', (error) => { reject(error); });
634634
response.pipe(createdFile);
635635
});
636-
request.on('error', (error) => { reject(); });
636+
request.on('error', (error) => { reject(error); });
637637
request.end();
638638
});
639639
}
@@ -663,10 +663,10 @@ export function downloadFileToStr(urlStr: string, headers?: OutgoingHttpHeaders)
663663
}
664664
let downloadedData: string = '';
665665
response.on('data', (data) => { downloadedData += data; });
666-
response.on('error', (error) => { reject(); });
666+
response.on('error', (error) => { reject(error); });
667667
response.on('end', () => { resolve(downloadedData); });
668668
});
669-
request.on('error', (error) => { reject(); });
669+
request.on('error', (error) => { reject(error); });
670670
request.end();
671671
});
672672
}

Extension/src/githubAPI.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,15 @@ function isRateLimit(input: any): input is RateLimit {
211211
async function getRateLimit(): Promise<RateLimit> {
212212
const header: OutgoingHttpHeaders = { 'User-Agent': 'vscode-cpptools' };
213213
const data: string = await util.downloadFileToStr('https://api.github.com/rate_limit', header)
214-
.catch(() => { throw new Error('Failed to download rate limit JSON'); });
214+
.catch((error) => {
215+
if (error.code && error.code !== "ENOENT") {
216+
// Only throw if the user is connected to the Internet.
217+
throw new Error('Failed to download rate limit JSON');
218+
}
219+
});
220+
if (!data) {
221+
return Promise.resolve(null);
222+
}
215223

216224
let rateLimit: any;
217225
try {
@@ -229,7 +237,7 @@ async function getRateLimit(): Promise<RateLimit> {
229237

230238
async function rateLimitExceeded(): Promise<boolean> {
231239
const rateLimit: RateLimit = await getRateLimit();
232-
return rateLimit.rate.remaining <= 0;
240+
return rateLimit && rateLimit.rate.remaining <= 0;
233241
}
234242

235243
/**
@@ -246,7 +254,15 @@ async function getReleaseJson(): Promise<Build[]> {
246254
const header: OutgoingHttpHeaders = { 'User-Agent': 'vscode-cpptools' };
247255

248256
const data: string = await util.downloadFileToStr(releaseUrl, header)
249-
.catch(() => { throw new Error('Failed to download release JSON'); });
257+
.catch((error) => {
258+
if (error.code && error.code !== "ENOENT") {
259+
// Only throw if the user is connected to the Internet.
260+
throw new Error('Failed to download release JSON');
261+
}
262+
});
263+
if (!data) {
264+
return Promise.resolve(null);
265+
}
250266

251267
// Parse the file
252268
let releaseJson: any;

0 commit comments

Comments
 (0)