···55use nu_engine::{command_prelude::*, eval_block};
66use nu_parser::{FlatShape, TokenContents, flatten_block, lex, parse};
77use nu_protocol::{
88- Config, PipelineData, Span,
88+ Config, ListStream, PipelineData, Span,
99 engine::{Call, EngineState, Stack, StateWorkingSet},
1010};
1111use serde::Serialize;
1212use std::{
1313+ io::Cursor,
1314 sync::{Arc, Mutex, OnceLock},
1415 time::UNIX_EPOCH,
1516};
···146147 );
147148148149 let mut working_set = StateWorkingSet::new(engine_state);
149149-150150- // Capture the start offset *before* adding the file, as this is the global offset
151151- // where our file begins.
152150 let start_offset = working_set.next_span_start();
153151 let block = parse(&mut working_set, Some("entry"), input.as_bytes(), false);
154152···180178 PipelineData::Empty,
181179 );
182180183183- let pipeline_data = result.map_err(cmd_err)?;
184184- let table_command = nu_command::Table;
181181+ let pipeline_data = result.map_err(cmd_err)?.body;
182182+ let signals = engine_state.signals().clone();
183183+184184+ // this is annoying but we have to collect here so we can uncover errors
185185+ // before passing the data off to Table, because otherwise Table
186186+ // can't properly handle the errors and panics (something about ShellErrorBridge
187187+ // having a non IO error in it somehow idk i dont care really)
188188+ // TODO: see if there is a way to do this without collecting the pipeline
189189+ let pipeline_data = match pipeline_data {
190190+ PipelineData::Empty => return Ok(()),
191191+ PipelineData::Value(Value::Error { error, .. }, _) => {
192192+ return Err(cmd_err(*error));
193193+ }
194194+ PipelineData::ByteStream(s, m) => match (s.span(), s.type_(), s.reader()) {
195195+ (span, ty, Some(r)) => {
196196+ use std::io::Read;
197197+ let v = r
198198+ .bytes()
199199+ .collect::<Result<Vec<u8>, _>>()
200200+ .map_err(|e| cmd_err(ShellError::Io(IoError::new(e, span, None))))?;
201201+ (v.len() > 0)
202202+ .then(|| {
203203+ PipelineData::byte_stream(
204204+ ByteStream::read(Cursor::new(v), span, signals, ty),
205205+ m,
206206+ )
207207+ })
208208+ .unwrap_or(PipelineData::Empty)
209209+ }
210210+ (_, _, None) => PipelineData::Empty,
211211+ },
212212+ PipelineData::ListStream(s, m) => {
213213+ let span = s.span();
214214+ let v = s
215215+ .into_iter()
216216+ .map(|val| val.unwrap_error().map_err(cmd_err))
217217+ .collect::<Result<Vec<Value>, _>>()?;
218218+ PipelineData::list_stream(ListStream::new(v.into_iter(), span, signals), m)
219219+ }
220220+ x => x,
221221+ };
222222+223223+ // TODO: idk what this does i copied it from PipelineData::print_table
224224+ // dunno if it matters, we can just use nu_command::Table and it works fine i think
225225+ let table_command = engine_state
226226+ .table_decl_id
227227+ .map(|decl_id| engine_state.get_decl(decl_id))
228228+ .filter(|command| command.block_id().is_some())
229229+ .unwrap_or(&nu_command::Table);
185230 let call = Call::new(pipeline_data.span().unwrap_or_else(Span::unknown));
186231187232 let res = table_command
188188- .run(engine_state, stack, &call, pipeline_data.body)
233233+ .run(engine_state, stack, &call, pipeline_data)
189234 .map_err(cmd_err)?;
190235191236 match res {
···195240 }
196241 PipelineData::ByteStream(s, _) => {
197242 for line in s.lines().into_iter().flatten() {
198198- let out = line.map_err(|e| CommandError {
199199- error: Report::new(e),
200200- start_offset,
201201- })?;
243243+ let out = line.map_err(cmd_err)?; // TODO: do we turn this into a Value ??? or is returning err fine
202244 print_to_console(&out, true);
203245 }
204246 }
···224266 STACK.get().unwrap().lock().expect("stack initialized"),
225267 );
226268227227- let result = std::panic::catch_unwind(move || {
228228- match run_command_internal(&mut engine_guard, &mut stack_guard, input) {
229229- Ok(_) => None,
230230- Err(cmd_err) => Some(format_error(
231231- cmd_err.error,
232232- input.to_owned(),
233233- cmd_err.start_offset,
234234- )),
235235- }
236236- });
237237- result.unwrap_or_else(|err| Some(format!("panicked: {err:?}")))
269269+ match run_command_internal(&mut engine_guard, &mut stack_guard, input) {
270270+ Ok(_) => None,
271271+ Err(cmd_err) => Some(format_error(
272272+ cmd_err.error,
273273+ input.to_owned(),
274274+ cmd_err.start_offset,
275275+ )),
276276+ }
238277}
239278240279#[wasm_bindgen]