Skip to content
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

Throwing an Error when passing empty array to helpers.ArrayElements #920

Closed
c0per opened this issue May 4, 2022 · 5 comments · Fixed by #921
Closed

Throwing an Error when passing empty array to helpers.ArrayElements #920

c0per opened this issue May 4, 2022 · 5 comments · Fixed by #921
Labels
c: bug Something isn't working has workaround Workaround provided or linked p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug

Comments

@c0per
Copy link
Contributor

c0per commented May 4, 2022

Describe the bug

When passing in an empty Array to helpers.ArrayElements, I'm hoping it to return an empty Array.
Instead it throws this Error:

Uncaught Error: Max 0 should be larger then min 1.
    at i0.number (https://cdn.esm.sh/v78/@faker-js/faker@6.3.1/deno/faker.js:2:2634645)
    at s0.arrayElements (https://cdn.esm.sh/v78/@faker-js/faker@6.3.1/deno/faker.js:4:7275)
    at <anonymous>:2:15

Reproduction

Simply faker.helpers.arrayElements([]);

Additional Info

I'm using version v6.3.1 on Deno.

@c0per c0per added the s: pending triage Pending Triage label May 4, 2022
@Shinigami92
Copy link
Member

Describe the bug

When passing in an empty Array to helpers.ArrayElements, I'm hoping it to return an empty Array. Instead it throws this Error:

Uncaught Error: Max 0 should be larger then min 1.
    at i0.number (https://cdn.esm.sh/v78/@faker-js/faker@6.3.1/deno/faker.js:2:2634645)
    at s0.arrayElements (https://cdn.esm.sh/v78/@faker-js/faker@6.3.1/deno/faker.js:4:7275)
    at <anonymous>:2:15

Reproduction

Simply faker.helpers.arrayElements([]);

Additional Info

I'm using version v6.3.1 on Deno.

It could take a while until we fix this due to we are working on v7
In the meanwhile please use yourArray.length > 0 ? faker.helpers.arrayElements(yourArray) : []

c0per added a commit to c0per/faker that referenced this issue May 4, 2022
c0per added a commit to c0per/faker that referenced this issue May 4, 2022
@c0per
Copy link
Contributor Author

c0per commented May 4, 2022

I looked a bit into the code. It's a rather simple fix. I'll open a PR if it's ok to merge.

@c0per
Copy link
Contributor Author

c0per commented May 4, 2022

It's #921

@Shinigami92 Shinigami92 linked a pull request May 4, 2022 that will close this issue
@Shinigami92
Copy link
Member

I will reopen this one, so no duplicates are created...
We can close it when we release v7
Alternatively we need to release a v6.3.2 and use cherry-pick, but as this is easyly workaroundable, we could at least wait if other bugs are found

@Shinigami92 Shinigami92 reopened this May 4, 2022
@Shinigami92 Shinigami92 added c: bug Something isn't working p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug and removed s: pending triage Pending Triage labels May 4, 2022
@Shinigami92 Shinigami92 moved this to Done in Faker Roadmap May 4, 2022
@Shinigami92 Shinigami92 added this to the v7 - Current Major milestone May 4, 2022
@import-brain import-brain added the has workaround Workaround provided or linked label May 4, 2022
@xDivisionByZerox
Copy link
Member

xDivisionByZerox commented Jun 13, 2022

This should be fixed in the current version (v7.2.0).
Working stackblitz.

For this reason, I will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working has workaround Workaround provided or linked p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants