{"record":{"id":"0246662420064a2c","repo":"hcengineering/platform","slug":"invalid-workspace-n-errors","errorCode":null,"errorMessage":"Invalid workspace: \\n${errors}","messagePattern":"Invalid workspace: \\\\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/importer/src/importer/builder.ts","lineNumber":231,"sourceCode":"\n    return this\n  }\n\n  validate (): ValidationResult {\n    // Perform cross-entity validation\n    this.validateSpacesReferences()\n    this.validateDocumentsReferences()\n\n    return {\n      isValid: this.errors.size === 0,\n      errors: this.errors\n    }\n  }\n\n  build (): ImportWorkspace {\n    const validation = this.validate()\n    if (this.strictMode && !validation.isValid) {\n      throw new Error(\n        'Invalid workspace: \\n' +\n          Array.from(validation.errors.values())\n            .map((e) => `    * ${e.path}: ${e.error}`)\n            .join(';\\n')\n      )\n    }\n\n    for (const [teamspacePath, docs] of this.documentsByTeamspace) {\n      const teamspace = this.teamspaces.get(teamspacePath)\n      if (teamspace !== undefined) {\n        const rootDocPaths = Array.from(docs.keys()).filter((docPath) => !this.documentParents.has(docPath))\n\n        for (const rootPath of rootDocPaths) {\n          this.buildDocumentHierarchy(rootPath, docs)\n        }\n\n        teamspace.docs = rootDocPaths.map((path) => docs.get(path)).filter(Boolean) as ImportDocument[]\n      }","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/packages/importer/src/importer/builder.ts#L213-L249","documentation":"WorkspaceBuilder.build() first runs validate(); in strictMode, if any validation errors were collected (duplicate issue numbers, invalid entities, broken references, etc.), it refuses to produce the ImportWorkspace and throws a single aggregated 'Invalid workspace' error listing every error path and message.","triggerScenarios":"Calling build() while strictMode is enabled and validate() returns isValid=false — i.e. any addError was recorded during add* calls or cross-entity reference validation (validateSpacesReferences, validateDocumentsReferences).","commonSituations":"Import data with dangling parent/space references; duplicate issue numbers in a project; malformed entities added via add* methods; enabling strict mode on legacy data that has known minor issues.","solutions":["Read the per-path error list in the message and fix each underlying data problem (duplicates, invalid fields, dangling references).","Re-run build() after corrections; iterate until validation passes.","If appropriate for your use case, disable strictMode (set builder strictMode=false) so build() proceeds and errors are reported as warnings instead of throwing.","Add pre-import validation on your source data to catch duplicates and broken references before calling add*."],"exampleFix":"// before\nconst builder = new WorkspaceBuilder({ strictMode: true })\nbuilder.build() // throws on any collected error\n// after — inspect non-strict results\nconst builder = new WorkspaceBuilder({ strictMode: false })\nconst ws = builder.build()\nconst { isValid, errors } = builder.validate()\nif (!isValid) console.log([...errors.values()])","handlingStrategy":"try-catch","validationCode":"const validation = builder.validate()\nif (!validation.isValid) {\n  for (const e of validation.errors.values()) console.error(`${e.path}: ${e.error}`)\n  throw new Error('Fix validation errors before build()')\n}","typeGuard":null,"tryCatchPattern":"try {\n  const workspace = builder.build()\n} catch (e) {\n  if ((e as Error).message.startsWith('Invalid workspace:')) {\n    // parse bulleted entries 'path: error' and fix each before rebuilding\n    console.error((e as Error).message)\n  } else throw e\n}","preventionTips":["Call validate() before build() and fix all reported paths first.","Use strictMode=false during data cleanup to collect all errors at once, then re-enable for production imports.","Pre-validate source data (duplicates, required fields, references) before feeding the builder.","Treat the bulleted error list as a checklist; each entry maps to a specific data file/path."],"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"}