{"record":{"id":"cc36d3499860073e","repo":"affaan-m/ECC","slug":"context-graph-relation-type-cannot-be-empty","errorCode":null,"errorMessage":"Context graph relation type cannot be empty","messagePattern":"Context graph relation type cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":3673,"sourceCode":"        Ok(ContextGraphCompactionStats {\n            entities_scanned,\n            duplicate_observations_deleted,\n            overflow_observations_deleted,\n            observations_retained,\n        })\n    }\n\n    pub fn upsert_context_relation(\n        &self,\n        session_id: Option<&str>,\n        from_entity_id: i64,\n        to_entity_id: i64,\n        relation_type: &str,\n        summary: &str,\n    ) -> Result<ContextGraphRelation> {\n        let relation_type = relation_type.trim();\n        if relation_type.is_empty() {\n            return Err(anyhow::anyhow!(\n                \"Context graph relation type cannot be empty\"\n            ));\n        }\n        let summary = summary.trim();\n        let timestamp = chrono::Utc::now().to_rfc3339();\n\n        self.conn.execute(\n            \"INSERT INTO context_graph_relations (\n                session_id, from_entity_id, to_entity_id, relation_type, summary, created_at\n             )\n             VALUES (?1, ?2, ?3, ?4, ?5, ?6)\n             ON CONFLICT(from_entity_id, to_entity_id, relation_type) DO UPDATE SET\n                session_id = COALESCE(excluded.session_id, context_graph_relations.session_id),\n                summary = CASE\n                    WHEN excluded.summary <> '' THEN excluded.summary\n                    ELSE context_graph_relations.summary\n                END\",\n            rusqlite::params![","sourceCodeStart":3655,"sourceCodeEnd":3691,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/session/store.rs#L3655-L3691","documentation":"When linking two entities, the relation write path trims relation_type and rejects empties with `Context graph relation type cannot be empty`. The relation type labels the edge (e.g. \"depends_on\", \"references\") and is required for meaningful graph traversal.","triggerScenarios":"Calling the relation API with relation_type = \"\" or whitespace — commonly when the edge label comes from a mapping table or analyzer output that returned nothing.","commonSituations":"Dependency analyzers with unmapped relationship kinds; generic graph importers where the edge label column is blank; refactors that renamed a relation constant but left one call site defaulting to empty.","solutions":["Pass a concrete relation type string for each edge creation site.","Map unknown analyzer kinds to an explicit \"related\" fallback instead of empty.","Trim/validate relation_type before calling; skip edges without a label.","Grep for relation-creation call sites to catch any passing a possibly-empty variable."],"exampleFix":"// before\nstore.add_context_graph_relation(from_id, to_id, &edge_label, &summary)?;\n// after\nlet rel = edge_label.trim();\nif !rel.is_empty() {\n    store.add_context_graph_relation(from_id, to_id, rel, &summary)?;\n}","handlingStrategy":"validation","validationCode":"const rel = relationType.trim();\nif (!rel) return; // unlabeled edge: skip\nawait api.addContextGraphRelation(fromId, toId, rel, summary);","typeGuard":"function hasRelationType(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n    store.add_context_graph_relation(from_id, to_id, &rel, &summary)?;\n} catch (e) {\n    if (String(e).includes('relation type cannot be empty')) {\n        store.add_context_graph_relation(from_id, to_id, \"related\", &summary)?;\n    } else throw e;\n}","preventionTips":["Maintain a whitelist of valid relation types and map unknowns to a fallback.","Grep all relation-creation call sites for possibly-empty label variables.","Use a newtype or enum for RelationType to make empty values unrepresentable.","Add boundary validation tests for blank relation labels."],"tags":["context-graph","relation","validation","empty-field"],"backgroundTag":"empty-required-field","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}