1
0
Fork 0

Minor fix to error handling

This commit is contained in:
Vili Sinervä 2025-02-26 22:52:32 +02:00
parent 02026c42e0
commit 3e4d3fad7d
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
3 changed files with 8 additions and 3 deletions

View file

@ -38,7 +38,10 @@ pub fn start_compiler() {
for line in lines.map_while(Result::ok) {
match compile(&line) {
Ok(_) => println!("\nCompilation OK :)\n"),
Err(e) => println!("\n{}\n", e),
Err(e) => println!(
"{}",
format!("{{\"error\": {}}}", json::stringify(format!("{e}")))
),
}
}
}

View file

@ -173,7 +173,9 @@ fn parse_term<'source>(
TokenType::Punctuation => match token.text {
"(" => parse_parenthesized(pos, tokens),
"{" => parse_block(pos, tokens),
_ => unreachable!(),
_ => Err(ParserError {
msg: format!("Unexpected {}", token),
}),
},
_ => Err(ParserError {
msg: format!("Unexpected {}", token),

View file

@ -39,7 +39,7 @@ fn handle_connection(mut stream: TcpStream) {
let response = match output {
Ok(output) => format!("{{\"program\": \"{output}\"}}"),
Err(e) => format!("{{\"error\": \"{e}\"}}"),
Err(e) => format!("{{\"error\": {}}}", json::stringify(format!("{e}"))),
};
stream.write_all(response.as_bytes()).unwrap();