Skip to content

Promisify of method without last argument callback - undefined beahvior #17569

@benjamingr

Description

@benjamingr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.promisesIssues and PRs related to ECMAScript promises.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions