From 206764839f987cf5204b277d49bef19b0e18d69c Mon Sep 17 00:00:00 2001 From: Ram Goli Date: Sun, 10 Dec 2017 18:50:19 +0000 Subject: [PATCH 1/3] doc: update promisify docs with behavior when bad arguments are passed Currently the documentation states that promisify() will result in undefined behavior if bad arguments are passed. This is not necessarily the case, since the behavior is well defined, but just not useful. Fixes: https://github.com/nodejs/node/issues/17569#issuecomment-350534501 --- doc/api/util.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/api/util.md b/doc/api/util.md index 033224ba0cc16c..26b74b2d6eb9a1 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -552,8 +552,10 @@ If there is an `original[util.promisify.custom]` property present, `promisify` will return its value, see [Custom promisified functions][]. `promisify()` assumes that `original` is a function taking a callback as its -final argument in all cases, and the returned function will result in undefined -behavior if it does not. +final argument in all cases. If `original` is not a function, `promisify()` +will throw an error. If `original` is a function but its last argument is not a +node-style callback, it will be still be passed a node-style callback as its last +argument anyways. ### Custom promisified functions @@ -588,6 +590,8 @@ doSomething[util.promisify.custom] = (foo) => { }); }; ``` +If `promisify.custom` is defined but is not a function, `promisify()` will +throw an error. ### util.promisify.custom