deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

Draft: dotenv: don't crash when permission is not granted to an env file

Open alexgleason opened this issue 2 years ago • 2 comments

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 call loadSync({ 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.

alexgleason avatar Aug 04 '23 18:08 alexgleason

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 04 '23 18:08 CLAassistant

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 understand this motivation, but I don't think it's a good idea to change the behavior based on given permission.

Maybe we can create an alternative endpoint (like dotenv/load_simple.ts (or whatever name)) that only loads .env to explicitly opt out from .env.defaults and .env.example behaviors. What do you think?

kt3k avatar Aug 14 '23 09:08 kt3k

Closing this as stale. In parse()'s current state, you can set the examplePath and defaultPath options to null to prevent this behavior.

iuioiua avatar Jul 16 '24 01:07 iuioiua