From 031d01bba5856ca9ebeb0646b902723b3cd4d9a3 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 3d37844318996d..8e3befcebf6ec2 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -553,8 +553,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 @@ -589,6 +591,8 @@ doSomething[util.promisify.custom] = (foo) => { }); }; ``` +If `promisify.custom` is defined but is not a function, `promisify()` will +throw an error. ### util.promisify.custom