nestjs/nest-cli

odd behavior when the config file can't be read

micalevisk opened this issue ยท 5 comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When we have some nest config file but the system user running the nodejs process has no permissions to read the file the CLI silently ignores that, which could lead to confusion. For example: someone changed the content of nest-cli.json but the CLI ends up using the default values due to missing permissions.

This behavior is due to the following lines:

} catch (err) {
return filenames.length > 0
? await this.readAnyOf(filenames.slice(1, filenames.length))
: undefined;
}

Minimum reproduction code

https://github.com/nestjs/typescript-starter

Steps to reproduce

git clone https://github.com/nestjs/typescript-starter
cd typescript-starter
npm install

## change the nest-cli.json to an invalid config (eg: change the entryFile)

chmod -r nest-cli.json

npm run start:dev # see no errors

Expected behavior

either exiting with an error due to a non-readable nest config file or a warning message.

Exiting with an error seems better to me but it would be breaking change if the present behavior is a feature not a bug

Package version

10.2.1

Other

I can make a PR to address this

I'd love to see a PR for this issue so yes please go ahead ๐Ÿ™

Hello, I'm new in the open source contribution community. I'm also interested in this issue. I wonder should we check the user's permission on file before actually reading it.

@major-winter what I'm doing so far is checking the exception thrown on reading, because this is an edge case

But I'm not done yet so you can open a PR to address this

Another thing that I'd do in the PR: use the fs.readFileSync instead of the promise-based API, for performance reasons

@micalevisk Great, I'll wait for your PR.

Let's track this here #2446