{"record":{"id":"48eb5af383ed9374","repo":"Egonex-AI/Understand-Anything","slug":"scan-artifact-does-not-match-the-required-shape","errorCode":null,"errorMessage":"Scan artifact does not match the required shape","messagePattern":"Scan artifact does not match the required shape","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/large-repo-benchmark.mjs","lineNumber":730,"sourceCode":"    !isNonNegativeInteger(scan.totalFiles) ||\n    scan.totalFiles !== scan.files.length ||\n    !isNonNegativeInteger(scan.filteredByIgnore) ||\n    !isRecord(scan.stats) ||\n    !isNonNegativeInteger(scan.stats.filesScanned) ||\n    scan.stats.filesScanned !== scan.totalFiles ||\n    !isStringCountMap(scan.stats.byCategory) ||\n    !isStringCountMap(scan.stats.byLanguage) ||\n    typeof scan.contentDigest !== 'string' ||\n    !/^[a-f0-9]{64}$/.test(scan.contentDigest) ||\n    scan.files.some(\n      (file) =>\n        !isRecord(file) ||\n        typeof file.path !== 'string' ||\n        file.path.length === 0 ||\n        !isNonNegativeInteger(file.sizeLines),\n    )\n  ) {\n    throw new Error('Scan artifact does not match the required shape');\n  }\n}\n\nfunction validateImportArtifact(imports) {\n  if (\n    !isRecord(imports) ||\n    imports.scriptCompleted !== true ||\n    !isRecord(imports.importMap) ||\n    !isRecord(imports.stats) ||\n    !isNonNegativeInteger(imports.stats.filesScanned) ||\n    !isNonNegativeInteger(imports.stats.filesWithImports) ||\n    !isNonNegativeInteger(imports.stats.totalEdges) ||\n    Object.values(imports.importMap).some(\n      (targets) =>\n        !Array.isArray(targets) ||\n        targets.some((target) => typeof target !== 'string'),\n    )\n  ) {","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/scripts/lib/large-repo-benchmark.mjs#L712-L748","documentation":"Thrown by validateScanArtifact when the scan stage's JSON output fails a structural guard. The validator checks that scan is an object with scriptCompleted===true, a files array, a totalFiles count equal to files.length, numeric filteredByIgnore and stats fields, string→count maps for byCategory/byLanguage, a 64-hex-char contentDigest, and that every file entry has a non-empty string path and a non-negative integer sizeLines. Any single violation throws.","triggerScenarios":"The scan-project stage crashed or was killed, leaving scriptCompleted false or missing; totalFiles was miscounted relative to files.length; a file entry lacks path/sizeLines; contentDigest is absent or not a SHA-256; byCategory/byLanguage contain non-integer values; the artifact is not an object.","commonSituations":"A bug in scan-project.mjs that aborts before setting scriptCompleted; truncation of the output file; a schema change in scan output not reflected in the validator; memory/timeout killing the scan partway; manual edits to the scan artifact.","solutions":["Re-run the scan stage and confirm it exits cleanly (scriptCompleted===true).","Inspect the scan artifact to find the first failing field (files.length vs totalFiles, missing path, bad digest).","Ensure the scan script version matches the validator version (no schema drift).","Check worker stderr/diagnostics for the underlying abort cause and fix it, then regenerate."],"exampleFix":"// before — scan artifact with scriptCompleted false triggers the throw\n// after — ensure scan-project.mjs sets scriptCompleted=true on success and re-run\n// (no code fix in the validator; repair the scan stage output)","handlingStrategy":"validation","validationCode":"function isValidScan(scan: unknown): boolean {\n  if (scan === null || typeof scan !== 'object' || Array.isArray(scan)) return false;\n  const s = scan as Record<string, any>;\n  if (s.scriptCompleted !== true) return false;\n  if (!Array.isArray(s.files) || s.totalFiles !== s.files.length) return false;\n  if (!/^[a-f0-9]{64}$/.test(String(s.contentDigest))) return false;\n  return s.files.every((f: any) => f && typeof f.path === 'string' && f.path.length > 0 && Number.isInteger(f.sizeLines) && f.sizeLines >= 0);\n}","typeGuard":"function isScanArtifact(v: unknown): boolean {\n  return isValidScan(v); // wraps the structural check above as a narrowing predicate\n}","tryCatchPattern":"try { validateScanArtifact(scan); } catch (e) { /* mark stage failed, capture stderr, do not proceed to import/batch stages */ throw e; }","preventionTips":["Ensure scan-project.mjs sets scriptCompleted=true only on a clean exit.","Keep scan output schema and validator in lockstep across versions.","Treat a thrown validation as a stage failure — never feed an invalid scan into later stages."],"tags":["benchmark","validation","schema","scan","integrity"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}