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(misc): guard against failure to decode file in migration #23069

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from '../../utils/logger';
import { Tree } from '../../generators/tree';
import { getProjects } from '../../generators/utils/project-configuration';

Expand Down Expand Up @@ -59,13 +60,23 @@ function parseEnvFile(tree: Tree, envFilePath: string) {
if (!tree.exists(envFilePath)) {
return;
}

let envFileContent = tree.read(envFilePath, 'utf-8');
if (!envFileContent) {
// envFileContent is null if we fail to read the file for any reason
// e.g. the file is not utf-8 encoded
logger.info(
`Unable to update ${envFilePath}. Nx interpolates environment variables in the form of $VAR_NAME. To escape the dollar sign, use \\$VAR_NAME.`
);
return;
}

envFileContent = envFileContent
.split('\n')
.map((line) => {
line = line.trim();

if (!line.includes('$')) {
if (!line || !line.includes('$')) {
return line;
}

Expand Down