mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:05:47 +02:00
Fix return setting last exit code (#14120)
# Description Fixes #14113 and #14112. # Tests + Formatting Added a test.
This commit is contained in:
@ -287,8 +287,8 @@ impl Stack {
|
||||
pub fn set_last_error(&mut self, error: &ShellError) {
|
||||
if let Some(code) = error.external_exit_code() {
|
||||
self.set_last_exit_code(code.item, code.span);
|
||||
} else {
|
||||
self.set_last_exit_code(1, Span::unknown());
|
||||
} else if let Some(code) = error.exit_code() {
|
||||
self.set_last_exit_code(code, Span::unknown());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1470,8 +1470,11 @@ impl ShellError {
|
||||
Some(Spanned { item, span })
|
||||
}
|
||||
|
||||
pub fn exit_code(&self) -> i32 {
|
||||
self.external_exit_code().map(|e| e.item).unwrap_or(1)
|
||||
pub fn exit_code(&self) -> Option<i32> {
|
||||
match self {
|
||||
Self::Return { .. } | Self::Break { .. } | Self::Continue { .. } => None,
|
||||
_ => self.external_exit_code().map(|e| e.item).or(Some(1)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_value(self, span: Span) -> Value {
|
||||
|
Reference in New Issue
Block a user