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
This commit is contained in:
Stefan Holderbach 2022-10-24 20:09:19 +02:00 committed by GitHub
parent ebca840d91
commit 79fd7d54b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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),
}