From da448216cc57204da135048069cf8c1367555ae4 Mon Sep 17 00:00:00 2001 From: Ram Goli Date: Sun, 10 Dec 2017 18:50:19 +0000 Subject: [PATCH] doc: clearify promisify behavior for bad arguments 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. PR-URL: https://github.com/nodejs/node/pull/17593 Fixes: https://github.com/nodejs/node/issues/17569 Reviewed-By: Anatoli Papirovski Reviewed-By: Rich Trott Reviewed-By: Ruben Bridgewater Reviewed-By: Benjamin Gruenbaum Reviewed-By: Jon Moss Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca --- 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 510b8c92ac9e5f..c284d023498dfc 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -512,8 +512,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.js style callback, it will still be passed a Node.js style callback +as its last argument. ### Custom promisified functions @@ -548,6 +550,8 @@ doSomething[util.promisify.custom] = (foo) => { }); }; ``` +If `promisify.custom` is defined but is not a function, `promisify()` will +throw an error. ### util.promisify.custom