Error detected unexpectedly
jansesun opened this issue · 1 comments
Recently, I encountered a weird problem when I wrapped fs.exists
as a deferred.promisify
. My codes as below:
var fs = require('fs'),
deferred = require('deferred'),
promisify = deferred.promisify,
exists = promisify(fs.exists);
exists('')(function(exist) {
console.log(exist);
});
Once my codes ran, an error that "false" is not an error object is thrown. I was very confused, and then dived into how the exception happened. I find that when the fs.exists
is executed normally, it will pass false
rather than null
to the parameter error
. Meanwhile, the function applyFn
in 'deferred/ext/function/call-ansyc.js' detects errors by error != null
. false != null
values true
, so the logic goes to the unexpected branch.
@jansesun fs.exists
is not a node callback style function, and deferred.promisify
is strictly reserved for functions which obey this contract.
fs.exists
is weird (and only) deviation in node.js API (originally it was path.exists
), and for this reason it is already deprecated and it's usage is discouraged. Rely on fs.lstat
instead.