Last active
July 29, 2018 03:46
-
-
Save altbdoor/39277a5e43c6813f0c58be0a6d20fea8 to your computer and use it in GitHub Desktop.
Fix 'unreadable file error' for node-sass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original from: https://github.com/sass/node-sass/pull/2386 | |
| https://github.com/marcosbozzani/node-sass/commit/266861b.diff | |
| Modified to include exponential backoff | |
| --- render.js.bak 2018-07-28 22:33:12.784523700 +0800 | |
| +++ render.js 2018-07-29 11:42:15.442878400 +0800 | |
| @@ -42,11 +42,13 @@ | |
| renderOptions.file = options.src; | |
| } | |
| + var retries = 0; | |
| var sourceMap = options.sourceMap; | |
| var destination = options.dest; | |
| var stdin = options.stdin; | |
| var success = function(result) { | |
| + retries = 0; | |
| var todo = 1; | |
| var done = function() { | |
| if (--todo <= 0) { | |
| @@ -105,7 +107,29 @@ | |
| }; | |
| var error = function(error) { | |
| - emitter.emit('error', chalk.red(JSON.stringify(error, null, 2))); | |
| + if (isFileUnreadable(error) && retries < 4) { | |
| + retries++; | |
| + setTimeout(() => sass.render(renderOptions, renderCallback), Math.pow(retries, 5)); | |
| + } | |
| + else { | |
| + emitter.emit('error', chalk.red(JSON.stringify(error, null, 2))); | |
| + } | |
| + }; | |
| + | |
| + var isFileUnreadable = function(error) { | |
| + var unreadable = typeof error.message === 'string' && | |
| + ( | |
| + error.message.startsWith('File to read not found or unreadable: ') || | |
| + error.message.startsWith('File to import not found or unreadable: ') | |
| + ); | |
| + | |
| + return unreadable; | |
| + // if (unreadable) { | |
| + // var file = error.message.split('not found or unreadable: ')[1].trim(); | |
| + // return fs.existsSync(file); | |
| + // } | |
| + | |
| + // return false; | |
| }; | |
| var renderCallback = function(err, result) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment