Skip to content

Commit

Permalink
Convert ShellError::AliasNotFound to named fields (nushell#11118)
Browse files Browse the repository at this point in the history
# Description

Part of nushell#10700

# User-Facing Changes

None

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
  • Loading branch information
drbrain authored and dmatos2012 committed Feb 20, 2024
1 parent 4a7f53b commit 251f540
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/nu-command/src/help/help_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ You can also learn more at https://www.nushell.sh/book/"#;
} else {
let result = help_aliases(engine_state, stack, call);

let result = if let Err(ShellError::AliasNotFound(_)) = result {
let result = if let Err(ShellError::AliasNotFound { .. }) = result {
help_commands(engine_state, stack, call)
} else {
result
Expand Down
12 changes: 6 additions & 6 deletions crates/nu-command/src/help/help_aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ pub fn help_aliases(
}

let Some(alias) = engine_state.find_decl(name.as_bytes(), &[]) else {
return Err(ShellError::AliasNotFound(span(
&rest.iter().map(|r| r.span).collect::<Vec<Span>>(),
)));
return Err(ShellError::AliasNotFound {
span: span(&rest.iter().map(|r| r.span).collect::<Vec<Span>>()),
});
};

let Some(alias) = engine_state.get_decl(alias).as_alias() else {
return Err(ShellError::AliasNotFound(span(
&rest.iter().map(|r| r.span).collect::<Vec<Span>>(),
)));
return Err(ShellError::AliasNotFound {
span: span(&rest.iter().map(|r| r.span).collect::<Vec<Span>>()),
});
};

let alias_expansion =
Expand Down
5 changes: 4 additions & 1 deletion crates/nu-protocol/src/shell_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,10 @@ pub enum ShellError {
/// The alias does not exist in the current scope. It might exist in another scope or overlay or be hidden.
#[error("Alias not found")]
#[diagnostic(code(nu::shell::alias_not_found))]
AliasNotFound(#[label("alias not found")] Span),
AliasNotFound {
#[label("alias not found")]
span: Span,
},

/// Failed to find a file during a nushell operation.
///
Expand Down

0 comments on commit 251f540

Please sign in to comment.