use serde_json::{Value, json};
use daedalus_planner::ExecutionPlan;
use daedalus_runtime::RuntimePlan;
use crate::EngineError;
pub fn render_error(err: &EngineError) -> Value {
match err {
EngineError::Config(msg) => json!({ "code": "config", "message": msg }),
EngineError::Io { path, source } => json!({
"code": "io",
"path": path,
"message": source.to_string(),
}),
EngineError::Registry(e) => json!({
"code": "registry",
"registry_code": format!("{:?}", e.code()),
"message": e.message(),
}),
EngineError::Planner(diags) => json!({
"code": "planner",
"diagnostics": diags,
}),
EngineError::Runtime(e) => json!({
"code": "runtime",
"message": e.to_string(),
}),
EngineError::BundleParse { path, error } => json!({
"code": "bundle_parse",
"path": path,
"message": error,
}),
#[cfg(feature = "gpu")]
EngineError::Gpu(e) => json!({
"code": "gpu",
"message": e.to_string(),
}),
EngineError::FeatureDisabled(flag) => json!({
"code": "feature_disabled",
"feature": flag,
}),
}
}
pub fn render_plan(plan: &ExecutionPlan) -> Result<Value, EngineError> {
serde_json::to_value(plan)
.map_err(|e| EngineError::Config(format!("serialize plan failed: {e}")))
}
pub fn render_runtime(runtime: &RuntimePlan) -> Result<Value, EngineError> {
serde_json::to_value(runtime)
.map_err(|e| EngineError::Config(format!("serialize runtime failed: {e}")))
}