{"record":{"id":"71db4f9d4c6a497f","repo":"affaan-m/ECC","slug":"invalid-entityname-label-label","errorCode":null,"errorMessage":"Invalid ${entityName}${label ? ` (${label})` : ''}: ${formatValidationErrors(result.errors)}","messagePattern":"Invalid (.+?)(.+?)\\)` : ''\\}: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/state-store/schema.js","lineNumber":84,"sourceCode":"function formatValidationErrors(errors = []) {\n  return errors\n    .map(error => `${error.instancePath || '/'} ${error.message}`)\n    .join('; ');\n}\n\nfunction validateEntity(entityName, payload) {\n  const validator = getEntityValidator(entityName);\n  const valid = validator(payload);\n  return {\n    valid,\n    errors: validator.errors || [],\n  };\n}\n\nfunction assertValidEntity(entityName, payload, label) {\n  const result = validateEntity(entityName, payload);\n  if (!result.valid) {\n    throw new Error(`Invalid ${entityName}${label ? ` (${label})` : ''}: ${formatValidationErrors(result.errors)}`);\n  }\n}\n\nmodule.exports = {\n  assertValidEntity,\n  formatValidationErrors,\n  readSchema,\n  validateEntity,\n};\n","sourceCodeStart":66,"sourceCodeEnd":94,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/state-store/schema.js#L66-L94","documentation":"assertValidEntity runs the entity's JSON-schema validator and throws with a consolidated list of validation errors if the payload does not conform. The label parameter lets callers annotate which logical record failed. All insert/upsert paths in the state store funnel through this guard.","triggerScenarios":"Calling insertDecision/insertGovernanceEvent/insertSkillRun/upsertInstallState/upsertWorkItem/upsertSession with a payload missing required fields, with wrong property types, or violating constraints (e.g. non-ISO dates, empty required strings).","commonSituations":"Constructing records by hand and forgetting a required column; migrating data from an older schema with different field types; passing null/undefined instead of a full payload object.","solutions":["Read the error's formatted validation path list and add/fix the named fields in the payload.","Run validateEntity(entityName, payload) directly to see the full error list before calling the insert/upsert API.","Align the payload to the current schema version - regenerate records from producers that emit the old shape.","Wrap the call in try/catch and log the payload for inspection when validation fails in batch jobs."],"exampleFix":"// before\nupsertWorkItem({ id: 'w-1' }); // missing required status\n// after\nupsertWorkItem({ id: 'w-1', status: 'open', title: 'Fix bug' });","handlingStrategy":"try-catch","validationCode":"const result = validateEntity('workItem', payload);\nif (!result.valid) console.error(formatValidationErrors(result.errors));","typeGuard":"const looksValid = (p) => p != null && typeof p === 'object';","tryCatchPattern":"try {\n  upsertWorkItem(payload);\n} catch (e) {\n  if (String(e.message).startsWith('Invalid workItem')) {\n    console.error('Payload rejected:', JSON.stringify(payload));\n  }\n  throw e;\n}","preventionTips":["Run validateEntity on payloads before insert/upsert in dev/test.","Keep producers and the schema in the same version window.","Write round-trip tests: insert then read back every entity type.","Log the full formatted validation errors, not just the message head."],"tags":["validation","schema","state-store"],"backgroundTag":"schema-validation-failed","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"}