Skip to content
This repository has been archived by the owner on Aug 24, 2020. It is now read-only.

Commit

Permalink
Fix 'unreadable file error' in watch mode after a save in vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosbozzani committed May 18, 2018
1 parent 94ce852 commit 266861b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ module.exports = function(options, emitter) {
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) {
Expand Down Expand Up @@ -105,7 +107,28 @@ module.exports = function(options, emitter) {
};

var error = function(error) {
emitter.emit('error', chalk.red(JSON.stringify(error, null, 2)));
if (isFileUnreadable(error) && retries < 1000) {
retries++;
sass.render(renderOptions, renderCallback);
}
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: ')
);

if (unreadable) {
var file = error.message.split('not found or unreadable: ')[1].trim();
return fs.existsSync(file);
}

return false;
};

var renderCallback = function(err, result) {
Expand Down

0 comments on commit 266861b

Please sign in to comment.