From a41ae72bc1a7ff07403356602f44cdb0bd0bba78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Cortier?= Date: Tue, 14 Dec 2021 14:49:48 -0500 Subject: [PATCH] Fix error propagration across `hash` commands (#493) --- crates/nu-command/src/hash/generic_digest.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/hash/generic_digest.rs b/crates/nu-command/src/hash/generic_digest.rs index ac7205f8ff..30a5f6b472 100644 --- a/crates/nu-command/src/hash/generic_digest.rs +++ b/crates/nu-command/src/hash/generic_digest.rs @@ -1,7 +1,7 @@ use nu_engine::CallExt; use nu_protocol::ast::{Call, CellPath}; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; +use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; use std::marker::PhantomData; pub trait HashDigest: digest::Digest + Clone { @@ -90,6 +90,11 @@ where Value::String { val, span } => (val.as_bytes(), *span), Value::Binary { val, span } => (val.as_slice(), *span), other => { + let span = match input.span() { + Ok(span) => span, + Err(error) => return Value::Error { error }, + }; + return Value::Error { error: ShellError::UnsupportedInput( format!( @@ -97,7 +102,7 @@ where other.get_type(), D::name() ), - input.span().unwrap_or_else(|_| Span::unknown()), + span, ), }; }