Skip to main content

entracte_lib/
renderer_log.rs

1/// Renderer-side error reporter. The web error boundary calls this
2/// from `componentDidCatch` so the crash lands in the same rotating
3/// log file as everything else, instead of vanishing into the webview
4/// devtools console where no end user ever looks.
5#[tauri::command]
6pub fn report_renderer_error(
7    message: String,
8    stack: Option<String>,
9    component_stack: Option<String>,
10) {
11    log::error!(
12        "renderer: {} | stack={} | component_stack={}",
13        message,
14        stack.as_deref().unwrap_or("<none>"),
15        component_stack.as_deref().unwrap_or("<none>")
16    );
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    fn report_renderer_error_accepts_full_args() {
25        report_renderer_error(
26            "boom".to_string(),
27            Some("at foo (a.js:1)".to_string()),
28            Some("in <App/>".to_string()),
29        );
30    }
31
32    #[test]
33    fn report_renderer_error_accepts_missing_optionals() {
34        report_renderer_error("boom".to_string(), None, None);
35    }
36}