Skip to content

Commit

Permalink
feat: added error message and exposes WASM error message (#141)
Browse files Browse the repository at this point in the history
* Updated the error msg with eprintln!
  • Loading branch information
carrycooldude authored May 27, 2023
1 parent 790671d commit d0b2ae1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/server/src/handlers/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use actix_web::{
web::{Bytes, Data},
HttpRequest, HttpResponse,
};
use std::{fs::File, sync::RwLock};
use std::{fs::File, io::Write, sync::RwLock};
use wws_router::Routes;
use wws_worker::io::WasmOutput;

Expand Down Expand Up @@ -75,7 +75,20 @@ pub async fn handle_worker(req: HttpRequest, body: Bytes) -> HttpResponse {
.run(&req, &body_str, store, vars, stderr_file.get_ref())
{
Ok(output) => (output, true),
Err(_) => (WasmOutput::failed(), false),
Err(error) => {
if let Some(stderr_file) = stderr_file.get_ref() {
if let Ok(mut stderr_file) = stderr_file.try_clone() {
stderr_file
.write_all(error.to_string().as_bytes())
.expect("Failed to write error to stderr_file");
} else {
eprintln!("{}", error);
}
} else {
eprintln!("{}", error);
}
(WasmOutput::failed(), false)
}
};

let mut builder = HttpResponse::build(
Expand Down

0 comments on commit d0b2ae1

Please sign in to comment.