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

Maybe throw an error if letters is empty? #428

Closed
bendytree opened this issue Jun 22, 2023 · 3 comments
Closed

Maybe throw an error if letters is empty? #428

bendytree opened this issue Jun 22, 2023 · 3 comments

Comments

@bendytree
Copy link

My code had the following bug which hung the server:

import { customAlphabet } from 'nanoid';
const alphabet = 'aeiou';
const nanoid = customAlphabet('', 10);
nanoid(); // hangs forever

Took a bit to find the issue. If letters is null or empty, might be a good spot to throw an error.

@ai
Copy link
Owner

ai commented Jun 22, 2023

Sorry, these extra checks don’t fit in an idea of nano-library.

Maybe we can do it by types?

@bendytree
Copy link
Author

Doesn't really make me any difference if the check is added; I just thought it'd be helpful for others. Fwiw - I opened the C# and Swift versions to see what they do. C# throws if letters is empty. Swift won't hang because it doesn't use a while(true) loop.

@ai
Copy link
Owner

ai commented Jun 23, 2023

If you know how to add it by types, please send PR.

Unfortunately, JS code for check we can’t add because it will bloat the JS footprint of this nano library (and will help for a very small part of users)

@ai ai closed this as completed Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants