Minor fix to error handling
This commit is contained in:
parent
02026c42e0
commit
3e4d3fad7d
3 changed files with 8 additions and 3 deletions
|
@ -38,7 +38,10 @@ pub fn start_compiler() {
|
||||||
for line in lines.map_while(Result::ok) {
|
for line in lines.map_while(Result::ok) {
|
||||||
match compile(&line) {
|
match compile(&line) {
|
||||||
Ok(_) => println!("\nCompilation OK :)\n"),
|
Ok(_) => println!("\nCompilation OK :)\n"),
|
||||||
Err(e) => println!("\n{}\n", e),
|
Err(e) => println!(
|
||||||
|
"{}",
|
||||||
|
format!("{{\"error\": {}}}", json::stringify(format!("{e}")))
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,9 @@ fn parse_term<'source>(
|
||||||
TokenType::Punctuation => match token.text {
|
TokenType::Punctuation => match token.text {
|
||||||
"(" => parse_parenthesized(pos, tokens),
|
"(" => parse_parenthesized(pos, tokens),
|
||||||
"{" => parse_block(pos, tokens),
|
"{" => parse_block(pos, tokens),
|
||||||
_ => unreachable!(),
|
_ => Err(ParserError {
|
||||||
|
msg: format!("Unexpected {}", token),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
_ => Err(ParserError {
|
_ => Err(ParserError {
|
||||||
msg: format!("Unexpected {}", token),
|
msg: format!("Unexpected {}", token),
|
||||||
|
|
|
@ -39,7 +39,7 @@ fn handle_connection(mut stream: TcpStream) {
|
||||||
|
|
||||||
let response = match output {
|
let response = match output {
|
||||||
Ok(output) => format!("{{\"program\": \"{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();
|
stream.write_all(response.as_bytes()).unwrap();
|
||||||
|
|
Reference in a new issue