Skip to content

Make error output for missing environment variables more specific - #19529

Merged
fdncred merged 5 commits into
nushell:mainfrom
lucperkins:env-var-not-found-error
Nov 14, 2026
Merged

fdncred merged 5 commits into
nushell:mainfrom
lucperkins:env-var-not-found-error

Conversation

@lucperkins

@lucperkins lucperkins commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #8543 by changing the error output for a missing environment variable to be more developer friendly.

Currently:

  Error: nu::shell::column_not_found

    × Cannot find column 'UNSET_VAR'
     ╭─[entry #1:1:1]
   1 │ $env.UNSET_VAR
     · ────┬───
     ·     ├── column 'UNSET_VAR' is missing in one or more values
     ·     ╰── value originates here
     ╰────
    help: If some rows have this column, try using 'UNSET_VAR?' for optional
          access, or pre-fill using the `default` command

Proposed:

  Error: nu::shell::env_variable_not_found

    x Environment variable 'UNSET_VAR' not found
     ,-[source:1:1]
   1 | $env.UNSET_VAR
     : ^^^^|^^^
     :     `-- environment variable not found
     `----
    help: use `$env.UNSET_VAR?` to get `null` if it isn't set, or `$env.UNSET_VAR? | default
          <value>` to fall back to a default

User-facing changes (Release notes)

Accessing an unset environment variable, like $env.UNSET_VAR, now raises a nu::shell::env_variable_not_found error rather than the more generic nu::shell::column_not_found error, and suggests using a construction like $env.UNSET_VAR? for optional access.

Additional notes

N/A

lucperkins and others added 2 commits November 13, 2026 14:18
Accessing an unset environment variable with `$env.FOO` used to raise
`nu::shell::column_not_found`, with a help hint about rows and the
`default` command that doesn't apply to environment variables. The
`LoadEnv` instruction now returns the existing `EnvVarNotFoundAtRuntime`
error instead, which resolves the FIXME left in `eval_ir.rs`.

Tests that asserted the old column error for env lookups are updated to
expect the new error.

Closes nushell#8543

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lucperkins
lucperkins force-pushed the env-var-not-found-error branch from 0959329 to 83e2da9 Compare November 13, 2026 22:38

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

$env.FOO now reports env_variable_not_found with the $env.FOO? hint everywhere I tried it: closures, def, each, do, and arguments to run and %$cmd. Two nits on the hint text are left.

Findings: 0 High severity · 0 Medium severity · 2 Low severity

Open (2)

Notes from my clanker, checked on 83e2da9. Built the branch and ran each case on the branch binary and on 0.117.1 (main 7bff3d1). CI's clippy, tests and typos are green on this head, so I didn't rerun them.

Comment thread crates/nu-engine/src/eval_ir.rs Resolved
Comment thread crates/nu-engine/src/eval_ir.rs Resolved
@lucperkins
lucperkins requested a review from fdncred November 14, 2026 00:41
@fdncred
fdncred merged commit 836bb49 into nushell:main Nov 14, 2026
26 of 27 checks passed
@fdncred

fdncred commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 14, 2026
@fdncred fdncred added A:error-handling How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error) notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:error-handling How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error) notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide better error output for missing environment variables

2 participants