Draft: dotenv: don't crash when permission is not granted to an env file #3516
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.
I'm having a problem with using
--allow-read=.env
It wants to read
.env.defaults
and.env.example
, which I don't care about.I think if you don't grant permission to those files, the application should not crash. It should continue on without them. For now, the only way around it is with
--allow-read=.env,.env.defaults,.env.example
(too verbose), or to callloadSync({ export: true, examplePath: null, defaultsPath: null })
(also too verbose)So I have made it not crash when the files are denied permission.
But there's another problem.
Deno.errors.PermissionDenied
can occur both for Deno permissions AND for OS file permissions.That seems like a flaw in Deno itself. You should be able to tell whether
PermissionDenied
is due to OS permissions or Deno permissions.The only way around that is a verbose check of the file against the permissions API.
It seems wrong. I wouldn't merge this code as-is. But I'm wondering if someone has ideas about what to do.