- Apply cargo fmt to Rust code with multiline error handling - Apply Prettier formatting to TypeScript code with trailing commas - Unify #[allow(non_snake_case)] attribute formatting - Remove unused ProviderNotFound error variant from error.rs - Add vitest-report.json to .gitignore to exclude test artifacts - Optimize readability of error handling chains with vertical alignment All tests passing: 22 Rust tests + 126 frontend tests
42 lines
1022 B
Rust
42 lines
1022 B
Rust
use serde::Serialize;
|
|
use std::sync::{OnceLock, RwLock};
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
pub struct InitErrorPayload {
|
|
pub path: String,
|
|
pub error: String,
|
|
}
|
|
|
|
static INIT_ERROR: OnceLock<RwLock<Option<InitErrorPayload>>> = OnceLock::new();
|
|
|
|
fn cell() -> &'static RwLock<Option<InitErrorPayload>> {
|
|
INIT_ERROR.get_or_init(|| RwLock::new(None))
|
|
}
|
|
|
|
pub fn set_init_error(payload: InitErrorPayload) {
|
|
if let Ok(mut guard) = cell().write() {
|
|
*guard = Some(payload);
|
|
}
|
|
}
|
|
|
|
pub fn get_init_error() -> Option<InitErrorPayload> {
|
|
cell().read().ok()?.clone()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn init_error_roundtrip() {
|
|
let payload = InitErrorPayload {
|
|
path: "/tmp/config.json".into(),
|
|
error: "broken json".into(),
|
|
};
|
|
set_init_error(payload.clone());
|
|
let got = get_init_error().expect("should get payload back");
|
|
assert_eq!(got.path, payload.path);
|
|
assert_eq!(got.error, payload.error);
|
|
}
|
|
}
|