◐ Shell
clean mode source ↗

Promisify of method without last argument callback - undefined beahvior

Currently, our documentation states:

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.

However, undefined behavior is a very "harsh" way to put what happens (since it implies the process can crash) and the behavior is pretty well defined.

  • If a non function is passed in - promisify throws. https://github.com/nodejs/node/blob/master/lib/internal/util.js#L257-L259
  • If a function is passed but its promisify.custom is specified but not a function - it throws.
  • If a function is passed, but its last argument is not a node style callback - it will treat it 'as if' its last argument is a node style callback - and will pass one to it as the last argument.

It won't do something useful but the behavior is defined.

I think our documentation should be amended to explain that the undefined behavior here isn't "as undefined" as writing out of bounds of a buffer for example.

I'm marking this as "good first issue", and "mentor available" in case someone wants to PR this but isn't sure how and would like guidance.