From 79fd7d54b21a62aa4e6aedc99563b242eef43da1 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Mon, 24 Oct 2022 20:09:19 +0200 Subject: [PATCH] Wrap `open` parse errors from `from` commands (#6877) * Wrap `open` parse errors from `from` commands Minimal fix for #6843 This propagates the underlying errors from the called `from` commands and adds a top-level error with the full path and the understood file extension and resulting called command. * Repoint inner span for `from ...` to `open` * Add actionable message: refer to help or use --raw --- crates/nu-command/src/filesystem/open.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index c298c2dec9..727ce249e3 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -172,8 +172,17 @@ impl Command for Open { let block = engine_state.get_block(block_id); eval_block(engine_state, stack, block, output, false, false) } else { - decl.run(engine_state, stack, &Call::new(arg_span), output) + decl.run(engine_state, stack, &Call::new(call_span), output) } + .map_err(|inner| { + ShellError::GenericError( + format!("Error while parsing as {}", ext), + format!("Could not parse '{}' with `from {}`", path.display(), ext), + Some(arg_span), + Some(format!("Check out `help from {}` or `help from` for more options or open raw data with `open --raw '{}'`", ext, path.display())), + vec![inner], + ) + }) } None => Ok(output), }