Add special error for calling metadata on $env and $nu (#11228)

Trying to call `metadata $env` or `metadata $nu` will throw an error:

```Nushell
~> metadata $nu                                                                                                                            
Error:   × Built-in variables `$env` and `$nu` have no metadata
   ╭─[entry #1:1:1]
 1 │ metadata $nu
   ·          ─┬─
   ·           ╰── no metadata available
   ╰────
```
This commit is contained in:
Andrej Kolchin 2023-12-04 18:49:36 +00:00 committed by GitHub
parent f8c82588b6
commit c9aa6ba0f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ use std::collections::{HashMap, HashSet};
use crate::engine::EngineState;
use crate::engine::DEFAULT_OVERLAY_NAME;
use crate::{ShellError, Span, Value, VarId};
use crate::{ENV_VARIABLE_ID, NU_VARIABLE_ID};
/// Environment variables per overlay
pub type EnvVars = HashMap<String, HashMap<String, Value>>;
@ -80,6 +81,16 @@ impl Stack {
}
}
if var_id == NU_VARIABLE_ID || var_id == ENV_VARIABLE_ID {
return Err(ShellError::GenericError(
"Built-in variables `$env` and `$nu` have no metadata".into(),
"no metadata available".into(),
Some(span),
None,
Vec::new(),
));
}
Err(ShellError::VariableNotFoundAtRuntime { span })
}