Skip to content

doc: mark the callback argument of crypto.generatePrime as mandatory #58299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mureinik
Copy link
Contributor

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.

This PR fixes the documentation and marks the callback argument as mandatory. The options (second) argument, is indeed optional, and is marked as such.

Fixes: #58298

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations. labels May 12, 2025
@mureinik mureinik force-pushed the generatePrime-doc branch from 729d702 to 51cc18d Compare May 12, 2025 19:16
@mureinik mureinik changed the title Mark the callback argument of crypto.generatePrime as mandatory doc: Mark the callback argument of crypto.generatePrime as mandatory May 12, 2025
@mureinik mureinik force-pushed the generatePrime-doc branch from 51cc18d to 44a7fd0 Compare May 12, 2025 19:17
@mureinik mureinik changed the title doc: Mark the callback argument of crypto.generatePrime as mandatory doc: mark the callback argument of crypto.generatePrime as mandatory May 12, 2025
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 `ERR_INVALID_ARG_TYPE` error:

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

This patch fixes the documentation and marks the callback argument as
mandatory. The `options` (second) argument, is indeed optional, and
is marked as such.

Fixes: nodejs#58298
@mureinik mureinik force-pushed the generatePrime-doc branch from 44a7fd0 to 4cf5fc2 Compare May 12, 2025 19:22
@panva panva added commit-queue Add this label to land a pull request using GitHub Actions. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crypto.generatePrime's callback argument should not be marked as optional
6 participants