{"record":{"id":"39e60221833357a1","repo":"affaan-m/ECC","slug":"invalid-install-state-label-label","errorCode":null,"errorMessage":"Invalid install-state${label ? ` (${label})` : ''}: ${formatValidationErrors(result.errors)}","messagePattern":"Invalid install-state(.+?)\\)` : ''\\}: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/install-state.js","lineNumber":277,"sourceCode":"function formatValidationErrors(errors = []) {\n  return errors\n    .map(error => `${error.instancePath || '/'} ${error.message}`)\n    .join('; ');\n}\n\nfunction validateInstallState(state) {\n  const validator = getValidator();\n  const valid = validator(state);\n  return {\n    valid,\n    errors: validator.errors || [],\n  };\n}\n\nfunction assertValidInstallState(state, label) {\n  const result = validateInstallState(state);\n  if (!result.valid) {\n    throw new Error(`Invalid install-state${label ? ` (${label})` : ''}: ${formatValidationErrors(result.errors)}`);\n  }\n}\n\nfunction createInstallState(options) {\n  const installedAt = options.installedAt || new Date().toISOString();\n  const state = {\n    schemaVersion: 'ecc.install.v1',\n    installedAt,\n    target: {\n      id: options.adapter.id,\n      target: options.adapter.target || undefined,\n      kind: options.adapter.kind || undefined,\n      root: options.targetRoot,\n      installStatePath: options.installStatePath,\n    },\n    request: {\n      profile: options.request.profile || null,\n      modules: Array.isArray(options.request.modules) ? [...options.request.modules] : [],","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/install-state.js#L259-L295","documentation":"assertValidInstallState validates an install-state object against the hand-rolled ecc.install.v1 schema (mirroring schemas/install-state.schema.json) and throws listing all validation errors. It runs on create, read, and write, so neither reading a corrupt state file nor writing a malformed state object can succeed silently.","triggerScenarios":"createInstallState/readInstallState/writeInstallState receive a state object missing required fields (e.g. version, installedAt), with wrong types, or an unrecognized ecc.install.v1 shape — validateInstallState returns valid:false and the formatted errors are thrown.","commonSituations":"Hand-editing .claude/install-state.json and dropping or renaming a required field; a plugin/schema version upgrade left an old state file that no longer validates; third-party tooling rewrote the state file with a different structure.","solutions":["Read the formatted validation errors in the message — they name the failing field and reason","Restore the missing/renamed field per schemas/install-state.schema.json (ecc.install.v1)","If the state file is from an older version, delete it and re-run the installer to regenerate it","Fix the code path if your own script built the state object and omitted required fields"],"exampleFix":"// before\n{ \"installedAt\": \"2026-01-01T00:00:00Z\" }\n// after — include the schema-required version field\n{ \"version\": \"ecc.install.v1\", \"installedAt\": \"2026-01-01T00:00:00Z\" }","handlingStrategy":"validation","validationCode":"// Validate against the published schema before use\nconst Ajv = require('ajv');\nconst schema = require('./schemas/install-state.schema.json');\nconst ajv = new Ajv();\nconst validate = ajv.compile(schema);\nif (!validate(state)) console.error(validate.errors); // fix before calling installer APIs","typeGuard":"function isInstallState(s) {\n  return !!s && typeof s === 'object' && !Array.isArray(s)\n    && s.version === 'ecc.install.v1'\n    && typeof s.installedAt === 'string';\n}","tryCatchPattern":"try {\n  const state = readInstallState();\n} catch (e) {\n  if (/^Invalid install-state/.test(e.message)) {\n    // recover: delete/regenerate the state file per ecc.install.v1 schema\n  } else throw e;\n}","preventionTips":["Always construct state objects via createInstallState rather than by hand","Keep the state file aligned with schemas/install-state.schema.json (ecc.install.v1)","After plugin/schema upgrades, regenerate the state file instead of reusing an old one"],"tags":["validation","schema","install-state"],"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"}