{"record":{"id":"2a6c5ee1ea291362","repo":"hcengineering/platform","slug":"invalid-type-at-path-n-errors-map-e","errorCode":null,"errorMessage":"Invalid ${type} at ${path}: \\n${errors.map((e) => `    * ${e}`).join('\\n')}","messagePattern":"Invalid (.+?) at (.+?): \\\\n(.+?)`\\)\\.join\\('\\\\n'\\)\\}","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/importer/src/importer/builder.ts","lineNumber":328,"sourceCode":"      if (template.docPrefix !== undefined) {\n        this.qmsTemplatePrefixCache.add(template.docPrefix)\n      }\n    }\n  }\n\n  private validateAndAdd<T, K>(\n    type: string,\n    path: string,\n    item: T,\n    validator: (item: T) => string[],\n    collection: Map<K, T>,\n    key?: K\n  ): void {\n    const errors = validator(item)\n    if (errors.length > 0) {\n      this.addError(path, `Invalid ${type} at ${path}: \\n${errors.map((e) => `    * ${e}`).join('\\n')}`)\n      if (this.strictMode) {\n        throw new Error(`Invalid ${type} at ${path}: \\n${errors.map((e) => `    * ${e}`).join('\\n')}`)\n      }\n    } else {\n      collection.set((key ?? path) as K, item)\n    }\n  }\n\n  private validateProjectType (projectType: ImportProjectType): string[] {\n    const errors: string[] = []\n    if (!this.validateStringDefined(projectType.name)) {\n      errors.push('name is required')\n    }\n    return errors\n  }\n\n  private validateProject (project: ImportProject): string[] {\n    const errors: string[] = []\n\n    errors.push(...this.validateType(project.title, 'string', 'title'))","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/packages/importer/src/importer/builder.ts#L310-L346","documentation":"WorkspaceBuilder.validateAndAdd runs the per-type validator on an item before storing it. If validation returns errors, it records them via addError and — only in strictMode — throws 'Invalid <type> at <path>' with the bulleted list of validation messages. In non-strict mode the item is not added but importing continues.","triggerScenarios":"Calling addProjectType/addProject/addTeamspace/addIssue/addDocument/addOrgSpace with an item whose validator returns a non-empty error array while strictMode is on (the throw path at builder.ts:329).","commonSituations":"Missing required fields (e.g. issue without number, project without name/type); values of wrong type from hand-built import data; items referencing undefined projects/spaces; programmatic generation of import data with gaps.","solutions":["Fix the data at <path> per the bulleted validation messages in the error and re-add the item.","Validate your source records before passing them to the builder's add* methods (check required fields and reference targets).","Run the import with strictMode=false to collect all validation errors instead of failing on the first one, then fix them in batch.","Check ordering: register referenced entities (projects, teamspaces, spaces) before items that depend on them."],"exampleFix":"// before\nbuilder.addIssue(projectPath, issuePath, { number: 42 } as ImportIssue)\n// after — include required fields\nbuilder.addIssue(projectPath, issuePath, {\n  number: 42,\n  title: 'Fix login',\n  description: 'Login fails on SSO',\n  state: 'todo'\n})","handlingStrategy":"validation","validationCode":"// validate items before add*\nconst errors = validateProject(project) // same rules as builder's validator\nif (errors.length > 0) {\n  throw new Error(`Refusing to add invalid project at ${path}: ${errors.join('; ')}`)\n}\nbuilder.addProject(path, project)","typeGuard":null,"tryCatchPattern":"try {\n  builder.addIssue(projectPath, issuePath, issue)\n} catch (e) {\n  if ((e as Error).message.startsWith('Invalid issue at')) {\n    console.error(`Fix data at ${issuePath}: ${e.message}`)\n  } else throw e\n}","preventionTips":["Check each item's required fields (title, number, state, etc.) before calling the add* methods.","Import/declare referenced entities (projects, teamspaces, spaces) before dependent items.","Run in strictMode=false first to enumerate all invalid items, fix them, then run strict.","Generate import data from typed models so missing required fields fail at compile time."],"tags":["importer","builder","validation","strict-mode"],"backgroundTag":"schema-validation-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}