Skip to content

crypto.generatePrime's callback argument should not be marked as optional #58298

@mureinik

Description

@mureinik

Affected URL(s)

https://nodejs.org/api/crypto.html#cryptogenerateprimesize-options-callback

Description of the problem

The current documentation lists the callback argument of crypto.generatePrime as optional (it's surrounded by square brackets), but this is incorrect - calling the function without a callback will result in an error:

> crypto.generatePrime(3)
Uncaught:
TypeError [ERR_INVALID_ARG_TYPE]: The "callback" argument must be of type function. Received undefined
    at Object.generatePrime (node:internal/crypto/random:476:3) {
  code: 'ERR_INVALID_ARG_TYPE'
}

For the record, the correct way to generate a prime synchronously, without a callback, is to use the generatePrimeSync API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions