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

🐛 Fix: zod EMAILER_ validation to handle empty strings #208

Conversation

that-one-arab
Copy link
Contributor

I ran the project only to get a zod error that my EMAILER_ fields need to contain at least 1 character. Weirdly enough the EMAILER_ env variables are optional.

This comes back to zod's way of handling empty strings, based on this comment from the creator of zod here

This PR implements the suggestion in the comment

This should prevent developer confusion when they have EMAILER_ env variables represented as empty strings not working when running locally, which should accelerate their onboarding process.

I ran the project only to get a zod error that my `EMAILER_` fields need to contain at least 1 character.
Weirdly enough the `EMAILER_` env variables are optional.

This comes back to `zod`'s way of handling empty strings, based on this comment from the creator of `zod` [here](colinhacks/zod#310 (comment))

This PR implements the suggestion in the comment

This should prevent developer confusion when they have `EMAILER_` env variables represented as empty strings not working when running locally, which should accelerate their onboarding process.
@tyler-dane
Copy link
Contributor

Thank you for taking the initiative to fix something you found frustrating as a dev.

However, I question whether others will run into the same issue, as we now have an .env.example file that shows the expected format of this value. I imagine they'd understand to simply change the placeholder value in place of the actual value rather than fall back to an empty string.

Accepting an empty string along with undefined for these values would help us avoid startup errors, but it would also open us up to more bugs from the overhead of supporting multiple types.

The general goal of the parsing in env.constants is to parse the .env, validate the inputs, and return a safe version object, where each property has one type. That lets developers have the confidence to work with environment values, rather than having to constantly think about the edge cases that might arise when supporting both undefined and ""

I'm going to close this for the above reasons. But if anyone else runs into this issue, we can link it to this PR and revisit.

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

Successfully merging this pull request may close these issues.

2 participants