From d92035d507adc8f8822bbb404836263e64b4fc02 Mon Sep 17 00:00:00 2001
From: prsabahrami
Date: Fri, 6 Sep 2024 12:29:55 -0400
Subject: [PATCH] Fix exit on syntax error
---
crates/shell/src/main.rs | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs
index 8d8ffdd..0ba916a 100644
--- a/crates/shell/src/main.rs
+++ b/crates/shell/src/main.rs
@@ -21,15 +21,24 @@ fn commands() -> HashMap> {
}
async fn execute(text: &str, state: &mut ShellState) -> anyhow::Result {
- let list = deno_task_shell::parser::parse(text)?;
+ let list = deno_task_shell::parser::parse(text);
+
+ let mut stderr = ShellPipeWriter::stderr();
+ let stdout = ShellPipeWriter::stdout();
+ let stdin = ShellPipeReader::stdin();
+
+ if let Err(e) = list {
+ let _ = stderr.write_line(&format!("Syntax error: {}", e));
+ return Ok(1);
+ }
// spawn a sequential list and pipe its output to the environment
let result = execute_sequential_list(
- list,
+ list.unwrap(),
state.clone(),
- ShellPipeReader::stdin(),
- ShellPipeWriter::stdout(),
- ShellPipeWriter::stderr(),
+ stdin,
+ stdout,
+ stderr,
AsyncCommandBehavior::Wait,
)
.await;