affaan-m/ECC · warning · anyhow::Error
Context graph entity type cannot be empty
Error message
Context graph entity type cannot be empty
What it means
Raised by upsert_context_entity in ecc2/src/session/store.rs:3099 when entity_type.trim().is_empty(). upsert_context_entity inserts/updates a row in context_graph_entities keyed by (entity_type, name, path); an empty type would corrupt the key and the semantic meaning of the entity, so it is rejected before any SQL runs.
Source
Thrown at ecc2/src/session/store.rs:3099
stats.messages_processed = stats.messages_processed.saturating_add(1);
}
}
Ok(stats)
}
pub fn upsert_context_entity(
&self,
session_id: Option<&str>,
entity_type: &str,
name: &str,
path: Option<&str>,
summary: &str,
metadata: &BTreeMap<String, String>,
) -> Result<ContextGraphEntity> {
let entity_type = entity_type.trim();
if entity_type.is_empty() {
return Err(anyhow::anyhow!("Context graph entity type cannot be empty"));
}
let name = name.trim();
if name.is_empty() {
return Err(anyhow::anyhow!("Context graph entity name cannot be empty"));
}
let normalized_path = path.map(str::trim).filter(|value| !value.is_empty());
let summary = summary.trim();
let entity_key = context_graph_entity_key(entity_type, name, normalized_path);
let metadata_json = serde_json::to_string(metadata)
.context("Failed to serialize context graph metadata")?;
let timestamp = chrono::Utc::now().to_rfc3339();
self.conn.execute(
"INSERT INTO context_graph_entities (
session_id, entity_key, entity_type, name, path, summary, metadata_json, created_at, updated_at
)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?8)View on GitHub (pinned to 01e15490f0)
Solutions
- Validate and normalize entity_type at the call site: trim and require a non-empty value, mapping empty to a sensible default like "note" or rejecting the record.
- If importing, filter out rows with empty types before calling upsert_context_entity.
- Add a debug_assert or a UI-level required-field check for entity type.
Example fix
// before
store.upsert_context_entity(Some(sid), "", name, path, summary, &meta)?;
// after: derive a default and guard
let entity_type = entity_type.trim();
if entity_type.is_empty() {
anyhow::bail!("entity_type is required for {name}");
}
store.upsert_context_entity(Some(sid), entity_type, name, path, summary, &meta)?; Defensive patterns
Strategy: validation
Validate before calling
// Centralize entity validation so the store never sees an empty type.
#[derive(Debug, Clone)]
pub struct ContextEntityType(String);
impl ContextEntityType {
pub fn new(raw: &str) -> anyhow::Result<Self> {
let trimmed = raw.trim();
if trimmed.is_empty() {
anyhow::bail!("context graph entity type cannot be empty");
}
Ok(Self(trimmed.to_string()))
}
pub fn as_str(&self) -> &str { &self.0 }
}
// upsert_context_entity takes &ContextEntityType, so callers must construct
// it through the validating constructor.
let etype = ContextEntityType::new(raw_type)?;
store.upsert_context_entity(sid, etype.as_str(), name, path, summary, &meta)?; Type guard
// ContextEntityType (above) is the type guard: it cannot represent an // empty string, so any value of this type satisfies the store's requirement.
Try / catch
// Validation happens before the call; the catch is for import pipelines.
for record in import_stream {
let etype = match ContextEntityType::new(&record.entity_type) {
Ok(t) => t,
Err(_) => { tracing::warn!("skipping entity with empty type: {:?}", record); continue; }
};
store.upsert_context_entity(sid, etype.as_str(), &record.name, record.path.as_deref(), &record.summary, &record.meta)?;
} Prevention
- Wrap entity_type in a newtype whose constructor rejects empty/whitespace values.
- During import, skip records with empty types rather than forwarding them.
- Add a UI-level required field for entity type.
- Co-locate validation so the store never receives empty strings.
When it happens
Trigger: Passing entity_type = "" or " " (whitespace only); passing a type derived from user input without trimming/validating; a default value leaking through when a caller forgot to populate the field.
Common situations: Bulk-importing context entities from a source where some rows have blank type columns; programmatic callers that build entity_type from an optional field that may be None->"".
Related errors
- Context graph entity name cannot be empty
- Context graph observation type cannot be empty
- Context graph observation summary cannot be empty
- Context graph relation type cannot be empty
- Context graph entity not found: {entity_id}
AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13).
Data as JSON: /api/errors/1f6506b6e1ce217c.
Report an issue: GitHub.