{"record":{"id":"30a17f0d8e6f40bf","repo":"spacedriveapp/spacedrive","slug":"source-entry-not-found-30a17f","errorCode":null,"errorMessage":"Source entry not found","messagePattern":"Source entry not found","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"core/src/service/sidecar_manager.rs","lineNumber":430,"sourceCode":"\t\tcontent_uuid: &Uuid,\n\t) -> Result<()> {\n\t\tlet db = library.db();\n\n\t\t// Find all reference sidecars for this content\n\t\tlet reference_sidecars = Sidecar::find()\n\t\t\t.filter(sidecar::Column::ContentUuid.eq(*content_uuid))\n\t\t\t.filter(sidecar::Column::SourceEntryId.is_not_null())\n\t\t\t.all(db.conn())\n\t\t\t.await?;\n\n\t\tfor sidecar in reference_sidecars {\n\t\t\tif let Some(source_entry_id) = sidecar.source_entry_id {\n\t\t\t\t// Get the source entry to find the file path\n\t\t\t\tuse crate::infra::db::entities::entry;\n\t\t\t\tlet source_entry = entry::Entity::find_by_id(source_entry_id)\n\t\t\t\t\t.one(db.conn())\n\t\t\t\t\t.await?\n\t\t\t\t\t.ok_or_else(|| anyhow::anyhow!(\"Source entry not found\"))?;\n\n\t\t\t\t// Compute the target sidecar path\n\t\t\t\tlet kind = sidecar\n\t\t\t\t\t.kind\n\t\t\t\t\t.as_str()\n\t\t\t\t\t.try_into()\n\t\t\t\t\t.map_err(|e: String| anyhow::anyhow!(e))?;\n\t\t\t\tlet variant = SidecarVariant::new(&sidecar.variant);\n\t\t\t\tlet format = sidecar\n\t\t\t\t\t.format\n\t\t\t\t\t.as_str()\n\t\t\t\t\t.try_into()\n\t\t\t\t\t.map_err(|e: String| anyhow::anyhow!(e))?;\n\n\t\t\t\tlet target_path = self\n\t\t\t\t\t.compute_path(&library.id(), content_uuid, &kind, &variant, &format)\n\t\t\t\t\t.await?;\n","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/service/sidecar_manager.rs#L412-L448","documentation":"A sidecar row has source_entry_id set, but entry::find_by_id returned no entry: the reference is orphaned. The lookup happens while processing reference sidecars, and the hard error aborts the whole operation instead of skipping the orphaned row.","triggerScenarios":"The source entry was deleted while its sidecars survived (missing cascade delete); a restored or edited database with referential inconsistencies; sidecars written for ephemeral entries that were later pruned.","commonSituations":"File deletion with failed cleanup; sync conflicts creating orphan rows; database imports.","solutions":["Add cleanup that removes sidecar rows whose source_entry_id no longer resolves, and run it once to fix existing orphans","Enforce referential integrity on entry delete (cascade or explicit sidecar cleanup)","Skip orphaned sidecars with a warning instead of failing the operation"],"exampleFix":"// before\nlet source_entry = entry::Entity::find_by_id(source_entry_id).one(db.conn()).await?.ok_or_else(|| anyhow::anyhow!(\"Source entry not found\"))?;\n\n// after\nlet Some(source_entry) = entry::Entity::find_by_id(source_entry_id).one(db.conn()).await? else {\n    warn!(%source_entry_id, \"orphaned sidecar: source entry missing, skipping\");\n    continue;\n};","handlingStrategy":"fallback","validationCode":"// Pre-filter reference sidecars to those with a resolvable source entry\nlet ids: Vec<Uuid> = reference_sidecars.iter().filter_map(|s| s.source_entry_id).collect();\nlet existing: HashSet<Uuid> = entry::Entity::find().filter(entry::Column::Id.is_in(ids)).all(db).await?.into_iter().map(|e| e.id).collect();","typeGuard":"fn has_source_entry(sidecar: &SidecarModel, existing: &HashSet<Uuid>) -> bool {\n    sidecar.source_entry_id.is_none_or(|id| existing.contains(&id))\n}","tryCatchPattern":"match entry::Entity::find_by_id(source_entry_id).one(db.conn()).await? {\n    Some(entry) => { /* use it */ }\n    None => {\n        warn!(%source_entry_id, \"orphaned sidecar: source entry missing, skipping\");\n        continue;\n    }\n}","preventionTips":["Cascade delete sidecars (or clean them up) when deleting source entries","Run a periodic orphan sweep over sidecar.source_entry_id","Skip-and-warn on unresolvable references instead of failing the operation"],"tags":["sidecar","data-integrity","foreign-key","orphans"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}