Skip to content

Crash on startup due to odd .env #264

Description

@jackarch-2

Hi,

We have some .env oddities in our codebase which are causing an issue where this CLI crashes on startup. I'm going to patch the CLI for myself using the prompt below, which I also wrote. If there's an alternative framing you'd propose to lead to a better solution, let me know and I'll go that way plus share the results in a PR. If taking a change like this upstream is undesirable, I totally understand that, too.

Anyway, here's my prompt for what it's worth, and please let me know if you're interested in collaborating more on an improvement here.

The Linear CLI crashes in our monorepo with this issue:

error: Uncaught (in promise) IsADirectory: Is a directory (os error 21): readfile '.env'
    return parse(await Deno.readTextFile(filepath));
                 ^
    at async Object.readTextFile (ext:deno_fs/30_fs.js:814:18)
    at async parseFile (https://jsr.io/@std/dotenv/0.225.6/mod.ts:244:18)
    at async load (https://jsr.io/@std/dotenv/0.225.6/mod.ts:217:26)
    at async loadEnvFiles (file:///var/folders/2b/8_tpkwdj7d574_pqq2j_dz2h0000gq/T/deno-compile-linear/src/config.ts:80:15)
    at async file:///var/folders/2b/8_tpkwdj7d574_pqq2j_dz2h0000gq/T/deno-compile-linear/src/config.ts:113:1
error: Uncaught (in promise) IsADirectory: Is a directory (os error 21): readfile '.env'
    return parse(await Deno.readTextFile(filepath));
                 ^
    at async Object.readTextFile (ext:deno_fs/30_fs.js:814:18)
    at async parseFile (https://jsr.io/@std/dotenv/0.225.6/mod.ts:244:18)
    at async load (https://jsr.io/@std/dotenv/0.225.6/mod.ts:217:26)
    at async loadEnvFiles (file:///var/folders/2b/8_tpkwdj7d574_pqq2j_dz2h0000gq/T/deno-compile-linear/src/config.ts:80:15)
    at async file:///var/folders/2b/8_tpkwdj7d574_pqq2j_dz2h0000gq/T/deno-compile-linear/src/config.ts:113:1
error: Uncaught (in promise) IsADirectory: Is a directory (os error 21): readfile '.env'
    return parse(await Deno.readTextFile(filepath));
                 ^
    at async Object.readTextFile (ext:deno_fs/30_fs.js:814:18)
    at async parseFile (https://jsr.io/@std/dotenv/0.225.6/mod.ts:244:18)
    at async load (https://jsr.io/@std/dotenv/0.225.6/mod.ts:217:26)
    at async loadEnvFiles (file:///var/folders/2b/8_tpkwdj7d574_pqq2j_dz2h0000gq/T/deno-compile-linear/src/config.ts:80:15)
    at async file:///var/folders/2b/8_tpkwdj7d574_pqq2j_dz2h0000gq/T/deno-compile-linear/src/config.ts:113:1 

It's because we have a weird structure with a .env directory. We also don't
follow popular .env file conventions; they may contain some zsh syntax in them
because SWEs typically source the files in their shell instead of treating them
as a true .env.

The Linear CLI shouldn't crash on startup if an invalid .env is encountered.
Handle this reasonably but more gracefully. Note that, ultimately, the issue is
our own unusual behavior in our codebase. Being entirely silent about the issue
may hide deeper issues and also would cause the Linear CLI to diverge from
industry standards. We can't mindlessly do that and instead need to strike a
compromise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions