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

enhance(libs/env): improve error message for bad .env configs #9673

Merged
merged 4 commits into from
Mar 28, 2024

Conversation

OnkarRuikar
Copy link
Contributor

@OnkarRuikar OnkarRuikar commented Sep 17, 2023

Summary

If there is a bad configuration in .env file then build throws following error:

yarn tool optimize-client-build
yarn run v1.22.19
$ ts-node tool/cli.ts optimize-client-build
(node:14158) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14158) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time

error: Unexpected token y in JSON at position 4

error Command failed with exit code 1.

This is very hard to debug because the error message doesn't give any details. The error is not in any .json file. And .env is not tracked using git so the changes don't show up in diffs.

Solution

Wrap JSON.parse in a function to throw an error with better message.

Following are the logs after the fix:

yarn tool optimize-client-build
yarn run v1.22.19
$ ts-node tool/cli.ts optimize-client-build
(node:13226) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13226) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time

error: Error parsing value 'truey' in .env file

error Command failed with exit code 1.

How did you test this change?

Ran yarn tool optimize-client-build before and after the fix.

@caugner caugner requested a review from a team as a code owner November 7, 2023 20:05
@github-actions github-actions bot added the idle label Jan 24, 2024
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions github-actions bot added merge conflicts 🚧 Please rebase onto or merge the latest main. and removed idle labels Mar 20, 2024
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions github-actions bot removed the merge conflicts 🚧 Please rebase onto or merge the latest main. label Mar 28, 2024
@caugner caugner changed the title chore(build): better error message for bad .env configs enhance(libs/env): improve error message for bad .env configs Mar 28, 2024
libs/env/index.js Outdated Show resolved Hide resolved
@caugner caugner merged commit f26f60c into mdn:main Mar 28, 2024
9 checks passed
@OnkarRuikar OnkarRuikar deleted the env_errors branch March 29, 2024 08:30
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