{"record":{"id":"fa607ff6ed6d7a98","repo":"hcengineering/platform","slug":"teamspace-teamspacepath-not-found","errorCode":null,"errorMessage":"Teamspace ${teamspacePath} not found","messagePattern":"Teamspace (.+?) not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/importer/src/importer/builder.ts","lineNumber":134,"sourceCode":"      this.addError(issuePath, `Duplicate issue number ${issue.number} in project ${projectPath}`)\n    } else {\n      this.validateAndAdd('issue', issuePath, issue, (i) => this.validateIssue(i), projectIssues, issuePath)\n\n      if (parentIssuePath !== undefined) {\n        this.issueParents.set(issuePath, parentIssuePath)\n      }\n    }\n    return this\n  }\n\n  addDocument (teamspacePath: string, docPath: string, doc: ImportDocument, parentDocPath?: string): this {\n    if (!this.documentsByTeamspace.has(teamspacePath)) {\n      this.documentsByTeamspace.set(teamspacePath, new Map())\n    }\n\n    const docs = this.documentsByTeamspace.get(teamspacePath)\n    if (docs === undefined) {\n      throw new Error(`Teamspace ${teamspacePath} not found`)\n    }\n\n    this.validateAndAdd('document', docPath, doc, (d) => this.validateDocument(d), docs, docPath)\n\n    if (parentDocPath !== undefined) {\n      this.documentParents.set(docPath, parentDocPath)\n    }\n\n    return this\n  }\n\n  addOrgSpace (path: string, space: ImportOrgSpace): this {\n    this.validateAndAdd('documentSpace', path, space, (s) => this.validateOrgSpace(s), this.qmsSpaces, path)\n    return this\n  }\n\n  addControlledDocument (\n    spacePath: string,","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/packages/importer/src/importer/builder.ts#L116-L152","documentation":"WorkspaceBuilder.addDocument keeps documents per teamspace in this.documentsByTeamspace and lazily creates the inner Map. The get() immediately after returning undefined triggers 'Teamspace <path> not found'. Like the issue variant, this is a defensive invariant that should be unreachable in sequential use since addDocument creates the entry when missing.","triggerScenarios":"addDocument called when the documentsByTeamspace entry for teamspacePath is removed/corrupted between has/set and get — e.g. external mutation of builder state, concurrency, or a subclass interfering.","commonSituations":"Running document processing concurrently against one builder; resetting builder internals mid-run; copying the builder object and operating on a stale shallow copy.","solutions":["Register the teamspace with addTeamspace(teamspacePath, ...) before adding documents under it.","Avoid concurrent or out-of-order calls into a single WorkspaceBuilder instance.","Audit any code that mutates or clones the builder's internal maps during processing.","If reproducible in plain sequential code, report as a bug."],"exampleFix":"// before\nbuilder.addDocument('ts/main', docPath, doc)\n// after\nbuilder.addTeamspace('ts/main', teamspace)\nbuilder.addDocument('ts/main', docPath, doc)","handlingStrategy":"try-catch","validationCode":"if (!builder.getTeamspaces().has(teamspacePath)) {\n  builder.addTeamspace(teamspacePath, teamspace)\n}","typeGuard":null,"tryCatchPattern":"try {\n  builder.addDocument(teamspacePath, docPath, doc)\n} catch (e) {\n  if ((e as Error).message === `Teamspace ${teamspacePath} not found`) {\n    console.error(`Builder state lost for teamspace ${teamspacePath}; re-add the teamspace first`)\n  } else throw e\n}","preventionTips":["Register teamspaces with addTeamspace before adding their documents.","Keep builder calls sequential; avoid sharing the builder between async workers.","Do not mutate internal maps from outside the class.","On this error, restart the build rather than retrying the single call."],"tags":["importer","builder","invariant","teamspace"],"backgroundTag":"internal-state-invariant","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}