{"record":{"id":"1f6506b6e1ce217c","repo":"affaan-m/ECC","slug":"context-graph-entity-type-cannot-be-empty","errorCode":null,"errorMessage":"Context graph entity type cannot be empty","messagePattern":"Context graph entity type cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":3099,"sourceCode":"                stats.messages_processed = stats.messages_processed.saturating_add(1);\n            }\n        }\n\n        Ok(stats)\n    }\n\n    pub fn upsert_context_entity(\n        &self,\n        session_id: Option<&str>,\n        entity_type: &str,\n        name: &str,\n        path: Option<&str>,\n        summary: &str,\n        metadata: &BTreeMap<String, String>,\n    ) -> Result<ContextGraphEntity> {\n        let entity_type = entity_type.trim();\n        if entity_type.is_empty() {\n            return Err(anyhow::anyhow!(\"Context graph entity type cannot be empty\"));\n        }\n        let name = name.trim();\n        if name.is_empty() {\n            return Err(anyhow::anyhow!(\"Context graph entity name cannot be empty\"));\n        }\n\n        let normalized_path = path.map(str::trim).filter(|value| !value.is_empty());\n        let summary = summary.trim();\n        let entity_key = context_graph_entity_key(entity_type, name, normalized_path);\n        let metadata_json = serde_json::to_string(metadata)\n            .context(\"Failed to serialize context graph metadata\")?;\n        let timestamp = chrono::Utc::now().to_rfc3339();\n\n        self.conn.execute(\n            \"INSERT INTO context_graph_entities (\n                session_id, entity_key, entity_type, name, path, summary, metadata_json, created_at, updated_at\n             )\n             VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?8)","sourceCodeStart":3081,"sourceCodeEnd":3117,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/session/store.rs#L3081-L3117","documentation":"The context-graph entity upsert trims entity_type and rejects empty values before building the entity key. An empty/whitespace-only entity_type yields `Context graph entity type cannot be empty`. This guards the entity key derivation, which would otherwise produce ambiguous rows.","triggerScenarios":"Calling upsert_context_graph_entity with entity_type = \"\" or \"   \" — e.g. callers deriving the type from a classifier result that returned empty, or defaulting a missing field to \"\".","commonSituations":"Metadata pipelines where the entity-type field is optional upstream but required here; parsing tool output where the type column is blank; config defaults of empty string.","solutions":["Provide a concrete entity type (e.g. \"file\", \"service\", \"person\") before calling.","Trim and validate entity_type at the call site; skip the entity entirely when absent.","Replace upstream defaults of \"\" with Option<String> so absence is explicit.","Log which caller produced the empty type to fix the source pipeline."],"exampleFix":"// before\nstore.upsert_context_graph_entity(\"\", &name, path, &summary, &meta)?;\n// after\nlet entity_type = detected_type.trim();\nif !entity_type.is_empty() {\n    store.upsert_context_graph_entity(entity_type, &name, path, &summary, &meta)?;\n}","handlingStrategy":"validation","validationCode":"const t = entityType.trim();\nif (!t) throw new Error('entity type required');\nawait api.upsertContextGraphEntity(t, name, path, summary, metadata);","typeGuard":"function hasEntityType(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n    store.upsert_context_graph_entity(&entity_type, &name, path, &summary, &meta)?;\n} catch (e) {\n    if (String(e).includes('entity type cannot be empty')) {\n        console.warn('skipping entity with blank type');\n    } else throw e;\n}","preventionTips":["Make entity_type a required, non-empty constructor/DTO field.","Trim classifier output and skip empty classifications.","Never default optional type fields to empty string; use Option/null.","Add unit tests asserting blank types are rejected at the call boundary."],"tags":["context-graph","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"}