Update project structure and configurations

This commit is contained in:
2026-05-23 10:19:55 +02:00
parent ab5dc7e568
commit 62efea0646
1832 changed files with 83568 additions and 51829 deletions

View File

@@ -1,10 +1,26 @@
//! Error handling for WASM bindings.
//!
//! Maps errors to JavaScript exceptions with human-readable messages.
//! Maps internal error types to JavaScript exceptions with human-readable messages.
use entropyk::ThermoError;
use wasm_bindgen::JsValue;
/// Convert a Result to a Result with JsValue error.
pub fn result_to_js<T, E: std::fmt::Display>(result: Result<T, E>) -> Result<T, JsValue> {
result.map_err(|e| js_sys::Error::new(&e.to_string()).into())
}
/// Map ThermoError to a human-readable JsValue.
pub fn thermo_error_to_js(e: ThermoError) -> JsValue {
let msg = match &e {
ThermoError::Component(err) => format!("Component error: {}", err),
ThermoError::Solver(err) => format!("Solver error: {}", err),
ThermoError::Fluid(err) => format!("Fluid error: {}", err),
ThermoError::Topology(err) => format!("Topology error: {}", err),
ThermoError::AddEdge(err) => format!("Edge error: {}", err),
ThermoError::Connection(err) => format!("Connection error: {}", err),
ThermoError::Constraint(err) => format!("Constraint error: {}", err),
_ => format!("{}", e),
};
js_sys::Error::new(&msg).into()
}