affaan-m/ECC · error

Context graph entity type cannot be empty

Error message

Context graph entity type cannot be empty

What it means

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.

Solutions

  1. Provide a concrete entity type (e.g. "file", "service", "person") before calling.
  2. Trim and validate entity_type at the call site; skip the entity entirely when absent.
  3. Replace upstream defaults of "" with Option<String> so absence is explicit.
  4. Log which caller produced the empty type to fix the source pipeline.

Example fix

// before
store.upsert_context_graph_entity("", &name, path, &summary, &meta)?;
// after
let entity_type = detected_type.trim();
if !entity_type.is_empty() {
    store.upsert_context_graph_entity(entity_type, &name, path, &summary, &meta)?;
}
Defensive patterns

Strategy: validation

Validate before calling

const t = entityType.trim();
if (!t) throw new Error('entity type required');
await api.upsertContextGraphEntity(t, name, path, summary, metadata);

Type guard

function hasEntityType(v) { return typeof v === 'string' && v.trim().length > 0; }

Try / catch

try {
    store.upsert_context_graph_entity(&entity_type, &name, path, &summary, &meta)?;
} catch (e) {
    if (String(e).includes('entity type cannot be empty')) {
        console.warn('skipping entity with blank type');
    } else throw e;
}

Prevention

When it happens

Trigger: 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 "".

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/1f6506b6e1ce217c. Report an issue: GitHub.

Appendix: 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 8321021c54)