{"record":{"id":"a24f82141b9b5931","repo":"affaan-m/ECC","slug":"invalid-provenance-metadata-validation-errors-j","errorCode":null,"errorMessage":"Invalid provenance metadata: ${validation.errors.join('; ')}","messagePattern":"Invalid provenance metadata: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/skill-evolution/provenance.js","lineNumber":136,"sourceCode":"    errors.push('confidence must be a number');\n  } else if (record.confidence < 0 || record.confidence > 1) {\n    errors.push('confidence must be between 0 and 1');\n  }\n\n  if (typeof record.author !== 'string' || record.author.trim().length === 0) {\n    errors.push('author is required');\n  }\n\n  return {\n    valid: errors.length === 0,\n    errors,\n  };\n}\n\nfunction assertValidProvenance(record) {\n  const validation = validateProvenance(record);\n  if (!validation.valid) {\n    throw new Error(`Invalid provenance metadata: ${validation.errors.join('; ')}`);\n  }\n}\n\nfunction readProvenance(skillPath, options = {}) {\n  const skillDir = normalizeSkillDir(skillPath);\n  const provenancePath = getProvenancePath(skillDir);\n  const provenanceRequired = options.required === true || requiresProvenance(skillDir, options);\n\n  if (!fs.existsSync(provenancePath)) {\n    if (provenanceRequired) {\n      throw new Error(`Missing provenance metadata for ${skillDir}`);\n    }\n\n    return null;\n  }\n\n  const record = JSON.parse(fs.readFileSync(provenancePath, 'utf8'));\n  assertValidProvenance(record);","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/skill-evolution/provenance.js#L118-L154","documentation":"assertValidProvenance runs a provenance record through validateProvenance and, if the record fails schema validation, throws with all validation errors joined by semicolons. It is the write/read path's integrity gate: provenance metadata must be complete and internally consistent before it is persisted or consumed.","triggerScenarios":"writeProvenance(record) with a record missing required fields (e.g. no name/version/source) or wrong field types; readProvenance encountering an on-disk PROVENANCE/JSON file whose contents fail validateProvenance; hand-edited provenance files with missing keys; records produced by an older library version that no longer satisfy the current schema.","commonSituations":"Manually editing provenance JSON and dropping a required field; merging skill directories without updating provenance; upgrading the plugin where validation rules tightened; partial writes/corruption leaving truncated JSON that parses but fails validation.","solutions":["Read the joined error list in the message and add/fix the named fields in the record.","Before writing, run validateProvenance(record) in the caller and repair fields programmatically.","Regenerate provenance for the skill with the library's own tooling instead of hand-editing the JSON.","If an old file fails new validation, migrate it: read the record, backfill missing fields per the current schema, then write it back."],"exampleFix":"// before\nwriteProvenance(dir, { name: 'my-skill' }); // missing version/source\n\n// after\nconst record = { name: 'my-skill', version: '1.0.0', source: 'ECC', ...rest };\nconst v = validateProvenance(record);\nif (v.valid) writeProvenance(dir, record);","handlingStrategy":"validation","validationCode":"const v = validateProvenance(record);\nif (!v.valid) {\n  console.error('Provenance issues:', v.errors.join('; '));\n  return null; // fix before writing\n}","typeGuard":"const isWellFormedProvenance = (r) => r !== null && typeof r === 'object' && typeof r.name === 'string' && r.name.length > 0;","tryCatchPattern":"try {\n  writeProvenance(dir, record);\n} catch (err) {\n  if (err.message.startsWith('Invalid provenance metadata')) {\n    console.error(err.message); // semicolon-joined field errors\n    // repair record fields named in the message, then retry once\n  } else throw err;\n}","preventionTips":["Always run validateProvenance before writeProvenance in your own scripts.","Never hand-edit provenance JSON; use the library's generation/update tooling.","After library upgrades, re-validate all on-disk provenance files and migrate them to the current schema."],"tags":["validation","schema","provenance"],"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"}