livingcss icon indicating copy to clipboard operation
livingcss copied to clipboard

File creation errors not propogated

Open matmar10 opened this issue 4 years ago • 0 comments

From: lib/generate.js

The following code uses CPS-style but it's within a promise chain.

The errors thrown are inside callbacks, hence they will never be returned up the promise chain.

      mkdirp(path.dirname(dest), function(err) {
        if (err) {
          // this has no effect on the promise chain, since it's inside a callback
          throw err;
        }

        fs.writeFile(dest, html, 'utf8', function(err) {
          if (err) {
            // this has no effect on the promise chain, since it's inside a callback
            throw err;
          }
        });

      });

Also, the following handling at the end will log errors from the promise chain, but will not allow them to propogate:

    .catch(function(err) {
      if (err) {
        console.error(err.stack);
      }
    });

matmar10 avatar Apr 05 '20 07:04 matmar10