-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add envalid
to improve script feedback when env vars are missing
#192
Merged
Conversation
This file contains 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
CiaranMn
previously approved these changes
Feb 4, 2022
kachkaev
commented
Feb 4, 2022
Comment on lines
+97
to
+106
const specFiles = getFileInfos( | ||
path.resolve(monorepoDirPath, "site/src/_pages/spec"), | ||
[], | ||
"spec", | ||
); | ||
const docsFiles = getFileInfos( | ||
path.resolve(monorepoDirPath, "site/src/_pages/docs"), | ||
[], | ||
"docs", | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CiaranMn I also fixed paths, which broke when I moved this script:
https://github.com/blockprotocol/blockprotocol/runs/5064081770?check_suite_focus=true
CiaranMn
approved these changes
Feb 4, 2022
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.
We were having issues with Algolia indexing recently and it was unclear whether it was because of missing or incorrect env vars. This PR introduces
envalid
, which improves script feedback. We can add this library to other scripts as needed.Before 🤔
After 💡
Feature summary
Caveats
By default,
envalid
callsprocess.exit
instead of throwing. This makes script output cleaner because it does not contain the call stack. We can’t usetry / catch
though. If we do want to usetry / catch
, we can implement a custom reporter, which would throw. This may be useful in server-side code, but I doubt about scripts.We need to use
import * as envalid from "envalid"
. Writingimport envalid from "envalid"
does not produce a TS error but crashes. This may change if we switch to native ESM modules.Specifying
choices
does not narrow the return type (i.e.env.EMAIL_TRANSPORT
isstring
, not"aws" | "none"
). This might be fixed via Ensure default values don't go through validation, fix type narrowing from defaults af/envalid#176Asana task (internal link)