linear-cli icon indicating copy to clipboard operation
linear-cli copied to clipboard

Crash on startup due to odd `.env`

Open jackarch-2 opened this issue 3 months ago • 2 comments

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.

jackarch-2 avatar Aug 26 '26 17:08 jackarch-2

The issue is more specifically here: https://github.com/schpet/linear-cli/blob/5af828699afa8ff2bbae1d9a8b3ff5e1f37f9bd7/src/config.ts#L84. If .env is a directory, we move on and try to load it.

I think the simplest solution is fine: silently do nothing for .env directories.

jackarch-2 avatar Aug 26 '26 17:08 jackarch-2

Shipped in v2.6.0.

Thanks for the report — the crash and the hang are both fixed.

  • A .env that is a directory no longer crashes the CLI on startup.
  • A .env written to be sourced by a shell no longer hangs forever; a self-referential value like export PATH=$PATH:/opt/bin used to spin the dotenv expander indefinitely.
  • An unusable .env is now reported as a warning on stderr and skipped, and the repository-root .env is still consulted as a fallback.
  • An unquoted $VAR in a LINEAR_/GH_/GITHUB_ value is skipped with a warning instead of expanded — expanding an unset variable silently produced the string "undefined".
  • LINEAR_IGNORE_ENV_FILE=1 skips .env loading entirely, for repositories whose .env is not dotenv-shaped.

Fixed by your #265 plus the follow-up in #269.

schpetbot avatar Sep 02 '26 19:09 schpetbot