{"record":{"id":"c166c34e34b2b072","repo":"Egonex-AI/Understand-Anything","slug":"invalid-input-analysispaths-must-be-an-array-when","errorCode":null,"errorMessage":"Invalid input: analysisPaths must be an array when provided","messagePattern":"Invalid input: analysisPaths must be an array when provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"understand-anything-plugin/skills/understand/extract-import-map.mjs","lineNumber":114,"sourceCode":"/**\n * Normalize a project-relative path to forward slashes (POSIX). Project-scanner\n * always emits forward slashes; we re-normalize to keep this script\n * cross-platform.\n */\nfunction toPosix(p) {\n  const separators = process.platform === 'win32' ? /[\\\\/]/ : /\\//;\n  return p.split(separators).filter(Boolean).join('/');\n}\n\n/**\n * Validate and normalize the optional selective-analysis path list. Keeping\n * this strict prevents an incremental caller from accidentally asking the\n * extractor to read outside projectRoot or silently miss a typo.\n */\nfunction selectAnalysisFiles(files, analysisPaths) {\n  if (analysisPaths === undefined) return files;\n  if (!Array.isArray(analysisPaths)) {\n    throw new Error('Invalid input: analysisPaths must be an array when provided');\n  }\n\n  const filesByPath = new Map();\n  for (const file of files) {\n    if (!file || typeof file.path !== 'string' || file.path.length === 0) {\n      throw new Error('Invalid input: every files entry must contain a non-empty path');\n    }\n    filesByPath.set(toPosix(file.path), file);\n  }\n\n  const selected = [];\n  const seen = new Set();\n  for (const rawPath of analysisPaths) {\n    if (typeof rawPath !== 'string' || rawPath.length === 0) {\n      throw new Error('Invalid input: every analysisPaths entry must be a non-empty string');\n    }\n    // Use the host's path semantics here. On POSIX, backslashes and drive-like\n    // prefixes are ordinary project-relative filename characters; on Windows,","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/07edf82a04371b6f69779b067bdc8a1a8753a9db/understand-anything-plugin/skills/understand/extract-import-map.mjs#L96-L132","documentation":"selectAnalysisFiles in extract-import-map.mjs treats `analysisPaths` as an optional restrictor: when omitted, all discovered files are analyzed. The option is strictly typed, so passing it in any non-array form (string, null, single path) throws this error to prevent accidental full-project scans or silent misreads during incremental extraction.","triggerScenarios":"Calling selectAnalysisFiles (or the extract-import-map entry) with options `{ analysisPaths: \"src/a.ts\" }` (a bare string), `{ analysisPaths: null }`, or a comma-joined string from CLI parsing, instead of an array of project-relative path strings.","commonSituations":"A CLI flag parsed with a default of null instead of undefined; a config file that stores analysisPaths as a comma-separated string; a caller intending 'no restriction' passing null rather than omitting the key; a refactor from a single `analysisPath` option to plural.","solutions":["Pass an array: `analysisPaths: [\"src/a.ts\", \"src/b.ts\"]`, with every entry a non-empty project-relative string.","To analyze everything, omit the `analysisPaths` key entirely — do not pass null.","Split comma-joined CLI values before calling: `value ? value.split(',') : undefined`.","Normalize null to undefined at the config-loading boundary so only arrays or undefined reach the extractor."],"exampleFix":"// before\nrunImportMap({ files, analysisPaths: \"src/a.ts\" });\n\n// after\nrunImportMap({ files, analysisPaths: [\"src/a.ts\"] }); // or omit key entirely","handlingStrategy":"type-guard","validationCode":"if (analysisPaths !== undefined && !Array.isArray(analysisPaths)) {\n  throw new TypeError('analysisPaths must be an array of project-relative strings or omitted');\n}","typeGuard":"function isAnalysisPaths(v) {\n  return v === undefined || (Array.isArray(v) && v.every(p => typeof p === 'string' && p.length > 0));\n}","tryCatchPattern":"try {\n  selectAnalysisFiles(files, analysisPaths);\n} catch (err) {\n  if (err.message.includes('analysisPaths must be an array')) {\n    console.error('Pass analysisPaths as an array (or omit it for all files), got:', typeof analysisPaths);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Normalize config at load time: `analysisPaths: cfg.analysisPaths == null ? undefined : [].concat(cfg.analysisPaths)`.","Split comma-joined CLI values before invoking the extractor.","Prefer omitting the key over passing null when you want the whole project analyzed.","Document in the caller that the option is array-or-undefined only."],"tags":["validation","type-mismatch","import-map","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"07edf82a04371b6f69779b067bdc8a1a8753a9db","analyzedAt":"2026-09-07T23:20:10.829Z","contentChangedAt":"2026-09-07T23:20:10.829Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}