{"record":{"id":"4b5def240da7ae65","repo":"hcengineering/platform","slug":"workspaceuuid-is-not-defined","errorCode":null,"errorMessage":"WorkspaceUuid is not defined","messagePattern":"WorkspaceUuid is not defined","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/presentation/src/collaborator.ts","lineNumber":25,"sourceCode":"//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n//\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\n\nimport { type CollaboratorClient, getClient as getCollaborator } from '@hcengineering/collaborator-client'\nimport { type Blob, type CollaborativeDoc, type Markup, type Ref } from '@hcengineering/core'\nimport { getMetadata } from '@hcengineering/platform'\n\nimport presentation from './plugin'\n\nfunction getClient (): CollaboratorClient {\n  const workspaceUuid = getMetadata(presentation.metadata.WorkspaceUuid)\n  if (workspaceUuid === undefined) {\n    throw new Error('WorkspaceUuid is not defined')\n  }\n\n  const token = getMetadata(presentation.metadata.Token) ?? ''\n  const collaboratorURL = getMetadata(presentation.metadata.CollaboratorUrl) ?? ''\n\n  return getCollaborator(workspaceUuid, token, collaboratorURL)\n}\n\n/** @public */\nexport async function getMarkup (doc: CollaborativeDoc, source: Ref<Blob> | null | undefined): Promise<Markup> {\n  const client = getClient()\n  return await client.getMarkup(doc, source)\n}\n\n/** @public */\nexport async function createMarkup (doc: CollaborativeDoc, markup: Markup): Promise<Ref<Blob>> {\n  const client = getClient()\n  return await client.createMarkup(doc, markup)","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/packages/presentation/src/collaborator.ts#L7-L43","documentation":"In the presentation package, `getClient` reads the WorkspaceUuid from plugin metadata and throws this Error when it is undefined. The CollaboratorClient requires a workspace UUID to connect, so collaboration cannot be set up without it. This guards against running presentation code in a context where the platform never injected the workspace metadata.","triggerScenarios":"Calling `getClient()` (directly or via `client`) when `getMetadata(presentation.metadata.WorkspaceUuid)` returns undefined — the metadata was never set by the host platform/plugin environment.","commonSituations":"Running the presentation outside the host application that supplies metadata, an older host version that doesn't set WorkspaceUuid, a typo/renamed metadata key, or plugin initialization order where metadata isn't populated yet.","solutions":["Ensure the host platform sets the WorkspaceUuid metadata before the presentation plugin initializes.","Verify the plugin registration/host version matches what the presentation package expects.","Check initialization order — call getClient only after the plugin's metadata has been injected.","Add an explicit startup check that logs which metadata keys are present to diagnose the missing value."],"exampleFix":"// before\nconst collaborator = getClient()\n// after\nconst collaborator = (() => {\n  try { return getClient() }\n  catch (e) {\n    console.error('Collaboration unavailable: workspace metadata missing', e)\n    return null\n  }\n})()","handlingStrategy":"try-catch","validationCode":"const wsUuid = getMetadata(presentation.metadata.WorkspaceUuid)\nif (wsUuid === undefined) {\n  throw new Error('Collaboration disabled: host did not provide WorkspaceUuid metadata')\n}","typeGuard":"function hasWorkspaceUuid(meta: Record<string, unknown>): meta is Record<string, string> {\n  return typeof meta[presentation.metadata.WorkspaceUuid as string] === 'string'\n}","tryCatchPattern":"let client: CollaboratorClient | null = null\ntry {\n  client = getClient()\n} catch (e) {\n  if ((e as Error).message === 'WorkspaceUuid is not defined') {\n    console.warn('Collaboration unavailable outside host environment')\n  } else throw e\n}","preventionTips":["Document that the presentation plugin requires host-injected metadata and degrade gracefully without it.","Verify host/platform version sets all required metadata keys before plugin init.","Lazy-initialize the collaborator client only after plugin metadata is confirmed present.","Add a diagnostic log of available metadata keys when collaboration fails to start."],"tags":["metadata","configuration","collaboration","plugin"],"backgroundTag":"missing-metadata","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}