mirror of
https://github.com/uqbar-dao/nectar.git
synced 2025-01-01 21:14:10 +03:00
kernel: print useful error message on process crash
This commit is contained in:
parent
c3419018ff
commit
18db99d54a
@ -10,7 +10,7 @@ use std::sync::Arc;
|
|||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use wasmtime::component::*;
|
use wasmtime::component::*;
|
||||||
use wasmtime::{Engine, Store};
|
use wasmtime::{Engine, Store};
|
||||||
use wasmtime_wasi::preview2::{Table, WasiCtx, WasiCtxBuilder, WasiView};
|
use wasmtime_wasi::preview2::{pipe::MemoryOutputPipe, Table, WasiCtx, WasiCtxBuilder, WasiView};
|
||||||
|
|
||||||
bindgen!({
|
bindgen!({
|
||||||
path: "wit",
|
path: "wit",
|
||||||
@ -53,6 +53,8 @@ impl WasiView for ProcessWasi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const STACK_TRACE_SIZE: usize = 5000;
|
||||||
|
|
||||||
pub async fn send_and_await_response(
|
pub async fn send_and_await_response(
|
||||||
process: &mut ProcessWasi,
|
process: &mut ProcessWasi,
|
||||||
source: Option<t::Address>,
|
source: Option<t::Address>,
|
||||||
@ -492,7 +494,8 @@ pub async fn make_process_loop(
|
|||||||
Process::add_to_linker(&mut linker, |state: &mut ProcessWasi| state).unwrap();
|
Process::add_to_linker(&mut linker, |state: &mut ProcessWasi| state).unwrap();
|
||||||
|
|
||||||
let table = Table::new();
|
let table = Table::new();
|
||||||
let wasi = WasiCtxBuilder::new().build();
|
let wasi_stderr = MemoryOutputPipe::new(STACK_TRACE_SIZE);
|
||||||
|
let wasi = WasiCtxBuilder::new().stderr(wasi_stderr.clone()).build();
|
||||||
|
|
||||||
wasmtime_wasi::preview2::command::add_to_linker(&mut linker).unwrap();
|
wasmtime_wasi::preview2::command::add_to_linker(&mut linker).unwrap();
|
||||||
|
|
||||||
@ -548,14 +551,16 @@ pub async fn make_process_loop(
|
|||||||
.await;
|
.await;
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(_) => {
|
||||||
|
let stderr = wasi_stderr.contents().into();
|
||||||
|
let stderr = String::from_utf8(stderr)?;
|
||||||
let _ = send_to_terminal
|
let _ = send_to_terminal
|
||||||
.send(t::Printout {
|
.send(t::Printout {
|
||||||
verbosity: 0,
|
verbosity: 0,
|
||||||
content: format!(
|
content: format!(
|
||||||
"\x1b[38;5;196mprocess {} ended with error: {}\x1b[0m",
|
"\x1b[38;5;196mprocess {} ended with error:\x1b[0m\n{}",
|
||||||
metadata.our.process,
|
metadata.our.process,
|
||||||
format!("{:?}", e).lines().last().unwrap(),
|
stderr,
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
Loading…
Reference in New Issue
Block a user