Skip to content

weightedArrayElement does not mention the possibility to throw in it's docs #4015

Description

@xDivisionByZerox

Description

Our coding guidelines for JSDocs state that a faker function that is able throw should that that in their JSDocs.

> If a function can throw an error (FakerError) you have to include the `@throws` tag with an explanation when an error could be thrown

While reviewing #3857 I noticed that faker.helpers.weightedArrayElement does not have any throw comments, while clearly having possible errors being thrown during runtime:

if (array.length === 0) {
throw new FakerError(
'weightedArrayElement expects an array with at least one element'
);
}
if (array.some((elt) => elt.weight <= 0)) {
throw new FakerError(
'weightedArrayElement expects an array of { weight, value } objects where weight is a positive number'
);
}

Task

Add JSDocs stating that the function can throw as described in our guidelines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: docsImprovements or additions to documentationgood first issueGood for newcomersm: helpersSomething is referring to the helpers modulep: 1-normalNothing urgent

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions