{"record":{"id":"bdca0f9fe44f1e24","repo":"JuliusBrussee/caveman","slug":"file-missing-id","errorCode":null,"errorMessage":"${file}: missing $id","messagePattern":"(.+?): missing \\$id","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-schemas.mjs","lineNumber":23,"sourceCode":"\nconst packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), \"..\");\nconst schemaRoot = path.join(packageRoot, \"schemas\");\nconst files = (await readdir(schemaRoot))\n  .filter((name) => name.endsWith(\".schema.json\"))\n  .sort();\n\nif (files.length === 0) {\n  throw new Error(\"no JSON schemas found\");\n}\n\nconst schemas = [];\nfor (const file of files) {\n  const schema = JSON.parse(await readFile(path.join(schemaRoot, file), \"utf8\"));\n  if (schema.$schema !== \"https://json-schema.org/draft/2020-12/schema\") {\n    throw new Error(`${file}: unsupported or missing $schema`);\n  }\n  if (typeof schema.$id !== \"string\" || schema.$id.length === 0) {\n    throw new Error(`${file}: missing $id`);\n  }\n  schemas.push(schema);\n}\n\nconst ajv = new Ajv2020({ allErrors: true, strict: true });\najv.addSchema(schemas);\nfor (const schema of schemas) {\n  const validate = ajv.getSchema(schema.$id);\n  if (!validate) throw new Error(`schema failed to compile: ${schema.$id}`);\n}\n\nconst agentFixtureRoot = path.join(packageRoot, \"fixtures\", \"agent\");\nconst fixtureFiles = (await readdir(agentFixtureRoot))\n  .filter((name) => name.endsWith(\".json\"))\n  .sort();\n\nif (fixtureFiles.length !== 2) {\n  throw new Error(`expected exactly 2 agent conformance fixtures, found ${fixtureFiles.length}`);","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-schemas.mjs#L5-L41","documentation":"Each schema must carry a non-empty string $id because the script registers all schemas in Ajv by $id and later resolves them via ajv.getSchema($id). A missing, non-string, or empty $id would make the schema unreferenceable, so the script throws naming the file.","triggerScenarios":"Running scripts/validate-schemas.mjs when a schema file omits $id, sets $id to a non-string (e.g. number or object), or sets it to \"\".","commonSituations":"New schema added without following the existing files' $id convention; a tool stripped $id during transformation; $id accidentally renamed to $ref or id.","solutions":["Add a unique absolute URI $id to the named schema, matching the convention https://caveman.so/schemas/<name>.schema.json","Ensure $id is a JSON string, not a nested object or number","Confirm no two schemas share the same $id (Ajv duplicate-id registration will then fail instead)"],"exampleFix":"// before\n{\n  \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n  \"type\": \"object\"\n}\n// after\n{\n  \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n  \"$id\": \"https://caveman.so/schemas/adapter-conformance.schema.json\",\n  \"type\": \"object\"\n}","handlingStrategy":"validation","validationCode":"for (const f of files) {\n  const s = JSON.parse(await readFile(path.join(schemaRoot, f), 'utf8'));\n  if (typeof s.$id !== 'string' || s.$id.length === 0) throw new Error(`${f}: $id must be a non-empty string`);\n}\nconst ids = schemas.map(s => s.$id);\nif (new Set(ids).size !== ids.length) throw new Error('duplicate $id values across schemas');","typeGuard":"const hasId = (s) => typeof s?.$id === 'string' && s.$id.length > 0;","tryCatchPattern":"try { loadSchemas(); } catch (e) { if (e.message.includes('missing $id')) { console.error('Add canonical $id to:', e.message); process.exitCode = 1; } else throw e; }","preventionTips":["Follow the existing $id URI convention when adding schemas","Check $id uniqueness when adding multiple schemas at once","Never rename $id without grepping for $ref usages"],"tags":["json-schema","ajv","schemas"],"backgroundTag":"empty-required-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}