{"record":{"id":"542bc125f2e7cb19","repo":"spacedriveapp/spacedrive","slug":"failed-to-parse-item-type","errorCode":null,"errorMessage":"Failed to parse item_type: {}","messagePattern":"Failed to parse item_type: (.+?)","errorType":"exception","errorClass":"CoreError","httpStatus":null,"severity":"error","filePath":"core/src/domain/space.rs","lineNumber":367,"sourceCode":"\t\tuse sea_orm::{ColumnTrait, EntityTrait, QueryFilter};\n\n\t\tlet item_models = space_item::Entity::find()\n\t\t\t.filter(space_item::Column::Uuid.is_in(ids.to_vec()))\n\t\t\t.all(db)\n\t\t\t.await?;\n\n\t\tlet mut results = Vec::new();\n\n\t\tfor item_model in item_models {\n\t\t\t// Fetch parent space to get space_id (UUID)\n\t\t\tlet space_model = space::Entity::find_by_id(item_model.space_id)\n\t\t\t\t.one(db)\n\t\t\t\t.await?;\n\n\t\t\tlet space_id = space_model.map(|s| s.uuid).unwrap_or(item_model.uuid);\n\n\t\t\tlet item_type: ItemType = serde_json::from_str(&item_model.item_type).map_err(|e| {\n\t\t\t\tcrate::common::errors::CoreError::Other(anyhow::anyhow!(\n\t\t\t\t\t\"Failed to parse item_type: {}\",\n\t\t\t\t\te\n\t\t\t\t))\n\t\t\t})?;\n\n\t\t\t// Look up group UUID from group_id if present\n\t\t\tlet group_id = if let Some(gid) = item_model.group_id {\n\t\t\t\tspace_group::Entity::find_by_id(gid)\n\t\t\t\t\t.one(db)\n\t\t\t\t\t.await?\n\t\t\t\t\t.map(|g| g.uuid)\n\t\t\t} else {\n\t\t\t\tNone\n\t\t\t};\n\n\t\t\t// Build resolved_file if entry_uuid exists\n\t\t\tlet resolved_file = if let Some(entry_uuid) = item_model.entry_uuid {\n\t\t\t\tlet entry_model = entry::Entity::find()","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/domain/space.rs#L349-L385","documentation":"SpaceItem hydration (core/src/domain/space.rs:367) parses the space_item.item_type TEXT column with serde_json::from_str into ItemType. Valid stored values are externally-tagged enum JSON: \"Overview\", \"Recents\", \"Favorites\", \"FileKinds\", \"Sources\", \"Redundancy\", or objects {\"Location\":{\"location_id\":\"...\"}}, {\"Volume\":{\"volume_id\":\"...\"}}, {\"Tag\":{\"tag_id\":\"...\"}}, {\"Path\":{\"sd_path\":...}}, {\"Source\":{\"source_id\":\"...\"}}. Any other string or malformed JSON fails the whole from_ query with this error.","triggerScenarios":"A space_item row whose item_type was written by another daemon version (renamed/added variant), hand-edited, or written as snake_case ('favorites' instead of '\"Favorites\"'); a UUID inside Location/Volume/Tag that is not valid UUID JSON also fails from_str.","commonSituations":"Version skew between clients and daemon sharing one library DB; downgraded builds; prototype clients writing items with a different serialization; truncated rows after a crash mid-write.","solutions":["Find bad rows: `SELECT id, item_type FROM space_item;` and eyeball values against the valid list above.","Fix or delete the offending row: UPDATE space_item SET item_type='\"Favorites\"' WHERE id=...; or DELETE the row and let the user re-add the item.","For renamed variants prefer #[serde(alias = \"...\")] so old rows keep parsing.","Re-index/rebuild the space if many rows are affected (space layout is derivable from groups + items)."],"exampleFix":"# before\nsqlite> SELECT item_type FROM space_item WHERE id=42;\nfavorites\n\n# after\nsqlite> UPDATE space_item SET item_type='\"Favorites\"' WHERE id=42;","handlingStrategy":"try-catch","validationCode":"// validate before insert: item_type column must always round-trip ItemType\nlet encoded = serde_json::to_string(&item_type)?;\nassert_eq!(\n    serde_json::from_str::<ItemType>(&encoded).ok().as_ref(),\n    Some(&item_type),\n    \"item_type encoding must be lossless\"\n);","typeGuard":"fn parse_item_type(s: &str) -> Option<ItemType> {\n    serde_json::from_str(s).ok()\n}","tryCatchPattern":"// skip-and-log per item so one bad row cannot break the whole space read\nlet item_type = match serde_json::from_str::<ItemType>(&item_model.item_type) {\n    Ok(t) => t,\n    Err(e) => {\n        tracing::warn!(item_id = %item_model.uuid, error = %e, \"dropping unparseable item\");\n        continue;\n    }\n};","preventionTips":["Encode item_type exclusively with serde_json::to_string(&ItemType).","Use serde aliases for variant renames; keep enums additive.","Run schema/version checks before opening a library created elsewhere."],"tags":["database","serde","spaces","data-corruption"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}