fix: treat blank optional env strings as undefined in API config - #160
Open
apatt124 wants to merge 1 commit into
Open
fix: treat blank optional env strings as undefined in API config#160apatt124 wants to merge 1 commit into
apatt124 wants to merge 1 commit into
Conversation
Seven fields in the API EnvSchema used z.string().trim().min(1).optional() without a preprocess step to coerce empty strings to undefined. When dotenv loads a blank value (e.g. VERCEL_TOKEN=) it produces an empty string, not undefined, so Zod's .optional() never applies and .min(1) fails. The same pattern was already solved correctly in the codebase for other optional fields (OptionalUrl, OptionalGithubOrganization, and FACILITY_PREVIEW_SURFACE_TOKEN all use a preprocess that converts blank strings to undefined). This change introduces an OptionalString helper that applies the same treatment and uses it for the affected fields: - VERCEL_TOKEN - VERCEL_OIDC_TOKEN - VERCEL_TEAM_ID - VERCEL_PROJECT_ID - FACILITY_AWS_CODEBUILD_PROJECT - FACILITY_AWS_CODEBUILD_CACHE_BASE_LOCATION - PACKAGE_REGISTRY_TOKEN Also adds *.pem to .gitignore. The quickstart guide instructs users to generate a GitHub App private key which downloads as a .pem file — a natural place to put it is the repo root, and it should be ignored by default to prevent accidental commits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Seven fields in
EnvSchemausedz.string().trim().min(1).optional()without a preprocess step to coerce empty strings toundefined. Whendotenvloads a blank value (e.g.VERCEL_TOKEN=) it produces"", notundefined, so Zod's.optional()never applies and.min(1)fails with a validation error at startup.Affected fields:
VERCEL_TOKENVERCEL_OIDC_TOKENVERCEL_TEAM_IDVERCEL_PROJECT_IDFACILITY_AWS_CODEBUILD_PROJECTFACILITY_AWS_CODEBUILD_CACHE_BASE_LOCATIONPACKAGE_REGISTRY_TOKENHow
The fix follows the pattern already established in the codebase for
OptionalUrl,OptionalGithubOrganization, andFACILITY_PREVIEW_SURFACE_TOKEN: a preprocess step that converts blank strings toundefinedbefore Zod's type checking runs. This change extracts that pattern into anOptionalStringhelper and applies it to the affected fields.How I found it
Hit this following the quickstart in the README. Running
pnpm devwith a fresh.env(generated from.env.example) crashes the API and worker immediately on startup because.env.exampleleaves these fields blank. The stack never comes up without either filling in Vercel/CodeBuild credentials you don't have, or manually deleting the blank lines.Also adds
*.pemto.gitignore— the quickstart guide instructs users to generate a GitHub App private key which downloads as a.pemfile, and the repo root is the natural place to put it.Verification
Confirmed locally: fresh
.envfrom.env.examplewith all optional fields blank, API and worker both start cleanly after this fix.