daedalus_engine/
diagnostics.rs1use serde_json::{Value, json};
2
3use daedalus_planner::ExecutionPlan;
4use daedalus_runtime::RuntimePlan;
5
6use crate::EngineError;
7
8pub fn render_error(err: &EngineError) -> Value {
10 match err {
11 EngineError::Config(msg) => json!({ "code": "config", "message": msg }),
12 EngineError::Io { path, source } => json!({
13 "code": "io",
14 "path": path,
15 "message": source.to_string(),
16 }),
17 EngineError::Registry(e) => json!({
18 "code": "registry",
19 "registry_code": format!("{:?}", e.code()),
20 "message": e.message(),
21 }),
22 EngineError::Planner(diags) => json!({
23 "code": "planner",
24 "diagnostics": diags,
25 }),
26 EngineError::Runtime(e) => json!({
27 "code": "runtime",
28 "message": e.to_string(),
29 }),
30 EngineError::BundleParse { path, error } => json!({
31 "code": "bundle_parse",
32 "path": path,
33 "message": error,
34 }),
35 #[cfg(feature = "gpu")]
36 EngineError::Gpu(e) => json!({
37 "code": "gpu",
38 "message": e.to_string(),
39 }),
40 EngineError::FeatureDisabled(flag) => json!({
41 "code": "feature_disabled",
42 "feature": flag,
43 }),
44 }
45}
46
47pub fn render_plan(plan: &ExecutionPlan) -> Result<Value, EngineError> {
49 serde_json::to_value(plan)
50 .map_err(|e| EngineError::Config(format!("serialize plan failed: {e}")))
51}
52
53pub fn render_runtime(runtime: &RuntimePlan) -> Result<Value, EngineError> {
55 serde_json::to_value(runtime)
56 .map_err(|e| EngineError::Config(format!("serialize runtime failed: {e}")))
57}