Skip to content

Provide better error output for missing environment variables #8543

Closed

Description

@lucperkins

Describe the bug

If the environment variable FOO isn't set in your environment and you run $env.FOO in Nushell, you get an error like this:

Error: nu::shell::column_not_found

  × Cannot find column
   ╭─[entry #1:1:1]
 1 │ echo $env.FOO
   ·      ──┬─ ─┬─
   ·        │   ╰── cannot find column 'FOO'
   ·        ╰── value originates here
   ╰────

While this output is technically correct, as Nushell sees the environment in terms of columns, I personally think it'd be more helpful to provide a more domain-specific error type and message, such as:

Error: nu::shell::env_var_not_set

  × Attempting to access an un-set environment variable
   ╭─[entry #1:1:1]
 1 │ echo $env.FOO
   ·      ──┬─ ─┬─
   ·        │   ╰── environment variable 'FOO' not set
   ·        ╰── value originates here
   ╰────

How to reproduce

Run $env.{VAR} for any unset {VAR}

Expected behavior

If I weren't already familiar with Nushell or with a specific bit of Nushell logic, I would expect to get more direct feedback when trying to access an un-set environment variable.

Screenshots

No response

Configuration

This should be the case with any Nushell config AFAIK.

Additional context

No response

Activity

  1. added
    A:error-unhelpful
    on Mar 20, 2023
  2. fdncred commented on Mar 20, 2023

    @fdncred
    Contributor

    Agreed. It would be nice to be more verbose with the error message.

  3. added
    good first issue
    on Mar 20, 2023
  4. harshalchaudhari35 commented on Mar 20, 2023

    @harshalchaudhari35
    Contributor

    @rgwood I can take this is up, if still available. I'm new to nushell and rust as a lang but with a bit of steer I can figure it out.

  5. rgwood commented on Mar 20, 2023

    @rgwood
    Contributor

    @harshalchaudhari35 This one might be a bit of a stretch for someone new to both Nushell and Rust, but feel free to give it a try.

  6. removed
    good first issue
    on Mar 28, 2023
  7. kaathewisegit commented on Nov 6, 2023

    @kaathewisegit
    Contributor

    The problem here is that follow_cell_path_helper doesn't know the record's name, and it can't get it from the span, because the global state isn't passed to it.

    In theory it could check if the record has config/theme/PATH fields, but this feels more like an ugly hack.

  8. kronberger-droid commented on Nov 13, 2026

    @kronberger-droid
    Contributor

    Still the generic error on 0.117.
    $env.FOO gives column_not_found with a help text about rows and default, which doesn't fit an environment variable.

  9. added a commit that references this issue on Nov 14, 2026
    836bb49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-unhelpful

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions