From b024dfe2a3d2006ff0c1668db1051bbf06bb514e Mon Sep 17 00:00:00 2001 From: Dirk Luijk Date: Fri, 17 Aug 2018 17:14:57 +0200 Subject: [PATCH 1/2] Catch XHR errors --- source-map-support.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source-map-support.js b/source-map-support.js index b853d1e..54ed4fa 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -80,13 +80,16 @@ retrieveFileHandlers.push(function(path) { var contents = null; if (!fs) { - // Use SJAX if we are in the browser - var xhr = new XMLHttpRequest(); - xhr.open('GET', path, false); - xhr.send(null); - var contents = null - if (xhr.readyState === 4 && xhr.status === 200) { - contents = xhr.responseText + try { + // Use SJAX if we are in the browser + var xhr = new XMLHttpRequest(); + xhr.open('GET', path, /** async */ false); + xhr.send(null); + if (xhr.readyState === 4 && xhr.status === 200) { + contents = xhr.responseText; + } + } catch (er) { + contents = ''; } } else if (fs.existsSync(path)) { // Otherwise, use the filesystem From f2e298f6f14f1acaa1ffc845b48430371c517bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Mon, 20 Aug 2018 12:21:15 +0100 Subject: [PATCH 2/2] Refactor try/catch --- source-map-support.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/source-map-support.js b/source-map-support.js index 54ed4fa..06ac0f9 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -78,9 +78,9 @@ retrieveFileHandlers.push(function(path) { return fileContentsCache[path]; } - var contents = null; - if (!fs) { - try { + var contents = ''; + try { + if (!fs) { // Use SJAX if we are in the browser var xhr = new XMLHttpRequest(); xhr.open('GET', path, /** async */ false); @@ -88,16 +88,12 @@ retrieveFileHandlers.push(function(path) { if (xhr.readyState === 4 && xhr.status === 200) { contents = xhr.responseText; } - } catch (er) { - contents = ''; - } - } else if (fs.existsSync(path)) { - // Otherwise, use the filesystem - try { + } else if (fs.existsSync(path)) { + // Otherwise, use the filesystem contents = fs.readFileSync(path, 'utf8'); - } catch (er) { - contents = ''; } + } catch (er) { + /* ignore any errors */ } return fileContentsCache[path] = contents;