This commit is contained in:
Sergio
2026-05-06 21:04:47 +00:00
parent d270c5e674
commit 90e5bd3c73
2 changed files with 9 additions and 6 deletions
+7 -4
View File
@@ -30,9 +30,10 @@ pub fn load_card_file(path: &Path) -> anyhow::Result<EntityCard> {
/// salidas de generadores que envuelven en `{"seed": {...}}`).
pub fn extract_card_from_json(raw: &str) -> anyhow::Result<EntityCard> {
let v: serde_json::Value = serde_json::from_str(raw)?;
if let Ok(c) = serde_json::from_value::<EntityCard>(v.clone()) {
return Ok(c);
}
let direct_err = match serde_json::from_value::<EntityCard>(v.clone()) {
Ok(c) => return Ok(c),
Err(e) => e,
};
if let serde_json::Value::Object(map) = v {
for (_, vv) in map {
if let Ok(c) = serde_json::from_value::<EntityCard>(vv) {
@@ -40,7 +41,9 @@ pub fn extract_card_from_json(raw: &str) -> anyhow::Result<EntityCard> {
}
}
}
anyhow::bail!("JSON no contiene una EntityCard válida")
// Propagamos el error del intento directo: es el caso típico (JSON top-level
// = EntityCard) y su mensaje apunta al campo concreto que rompió.
anyhow::bail!("JSON no contiene una EntityCard válida: {direct_err}")
}
/// Carga reglas desde un archivo JSON.
+2 -2
View File
@@ -1,6 +1,6 @@
{
"schema_version": 1,
"id": "01KQVPSMINBOOT0000000000AA",
"id": "01HQAR53D4M2NBV8KZTYXFGS01",
"lineage": null,
"label": "vps-min",
"provides": ["Spawn", "Journal"],
@@ -19,7 +19,7 @@
"genesis": [
{
"schema_version": 1,
"id": "01KQVPSMINBOOT0000000001SL",
"id": "01HQAR53D4M2NBV8KZTYXFGS02",
"lineage": null,
"label": "heartbeat-sleep",
"provides": [],