{"record":{"id":"87c35b46f84c6220","repo":"affaan-m/ECC","slug":"invalid-installstate-identity-expected-targetid-a","errorCode":null,"errorMessage":"Invalid installState identity: expected targetId and targetRoot","messagePattern":"Invalid installState identity: expected targetId and targetRoot","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/state-store/queries.js","lineNumber":353,"sourceCode":"function normalizeInstallStateInput(installState) {\n  return {\n    targetId: installState.targetId,\n    targetRoot: installState.targetRoot,\n    profile: installState.profile ?? null,\n    modules: installState.modules === undefined || installState.modules === null\n      ? []\n      : installState.modules,\n    operations: installState.operations === undefined || installState.operations === null\n      ? []\n      : installState.operations,\n    installedAt: installState.installedAt || new Date().toISOString(),\n    sourceVersion: installState.sourceVersion ?? null,\n  };\n}\n\nfunction normalizeInstallStateIdentity(identity) {\n  if (!identity || typeof identity !== 'object') {\n    throw new Error('Invalid installState identity: expected targetId and targetRoot');\n  }\n\n  const targetId = identity.targetId;\n  const targetRoot = identity.targetRoot;\n  if (typeof targetId !== 'string' || targetId.length === 0) {\n    throw new Error('Invalid installState identity: targetId must be a non-empty string');\n  }\n  if (typeof targetRoot !== 'string' || targetRoot.length === 0) {\n    throw new Error('Invalid installState identity: targetRoot must be a non-empty string');\n  }\n\n  return { targetId, targetRoot };\n}\n\nfunction normalizeGovernanceEventInput(governanceEvent) {\n  return {\n    id: governanceEvent.id,\n    sessionId: governanceEvent.sessionId ?? null,","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/state-store/queries.js#L335-L371","documentation":"normalizeInstallStateIdentity requires an object with targetId and targetRoot. When the identity argument is missing entirely, not an object (string, number, array), or null/undefined, this generic message is thrown before field-level checks run. The per-field variants (targetId/targetRoot empty) come later, so this error specifically means the identity itself was absent or the wrong type.","triggerScenarios":"Calling an installState query/upsert without the identity argument; passing the record instead of its identity sub-object; passing an array of identities; forwarding an undefined variable because an earlier lookup returned nothing.","commonSituations":"API misuse after a refactor moved identity out of the options object; destructuring an empty row from a previous query and passing the result; scripts passing a target path string where an identity object is expected.","solutions":["Pass an object: { targetId, targetRoot } with both non-empty strings","If you have a full install-state record, pass state.identity (or build identity from target.id and target.root)","Check the earlier lookup that produced the value — it returned undefined, so fix the lookup or guard against it","Read the function signature to confirm whether identity is a separate argument or nested in options"],"exampleFix":"// before\ngetInstallState(record); // whole record, not identity\n// after\ngetInstallState({ targetId: record.target.id, targetRoot: record.target.root });","handlingStrategy":"type-guard","validationCode":"function isValidIdentity(x) {\n  return x !== null && typeof x === 'object' && !Array.isArray(x);\n}\nif (!isValidIdentity(identity)) {\n  throw new Error('installState identity object required');\n}","typeGuard":"function isIdentity(x) {\n  return typeof x === 'object' && x !== null && 'targetId' in x && 'targetRoot' in x;\n}","tryCatchPattern":"try {\n  return getInstallState(identity);\n} catch (err) {\n  if (err.message.includes('Invalid installState identity')) {\n    console.error('Identity missing — resolve target before querying state');\n    return null;\n  } throw err;\n}","preventionTips":["Guard against undefined from prior lookups before forwarding values","Pass only the { targetId, targetRoot } pair, not whole records or arrays","Keep identity construction in one helper used by all call sites","Check function signatures after refactors that move identity into/out of options"],"tags":["validation","identity"],"backgroundTag":"missing-required-argument","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"}