{"record":{"id":"a6bc5f668e274ac8","repo":"toeverything/AFFiNE","slug":"space-not-found","errorCode":"space_not_found","errorMessage":"Space ${spaceId} not found.","messagePattern":"Space (.+?) not found\\.","errorType":"exception","errorClass":"SpaceNotFound","httpStatus":404,"severity":"error","filePath":"packages/backend/server/src/core/workspaces/resolvers/workspace.ts","lineNumber":176,"sourceCode":"    );\n\n    return workspaces.map(workspace => ({\n      ...workspace,\n      permission: map.get(workspace.id),\n      role: map.get(workspace.id),\n    }));\n  }\n\n  @Query(() => WorkspaceType, {\n    description: 'Get workspace by id',\n  })\n  async workspace(@CurrentUser() user: CurrentUser, @Args('id') id: string) {\n    await this.ac.user(user.id).workspace(id).assert('Workspace.Read');\n\n    const workspace = await this.models.workspace.get(id);\n\n    if (!workspace) {\n      throw new SpaceNotFound({ spaceId: id });\n    }\n\n    return workspace;\n  }\n\n  @Query(() => WorkspaceRolePermissions, {\n    description: 'Get workspace role permissions',\n    deprecationReason: 'use WorkspaceType[permissions] instead',\n  })\n  async workspaceRolePermissions(\n    @CurrentUser() user: CurrentUser,\n    @Args('id') id: string\n  ): Promise<WorkspaceRolePermissions> {\n    const { role, permissions } = await this.ac\n      .user(user.id)\n      .workspace(id)\n      .permissions();\n","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/2af30773aecd567f09b346e7b72fc69143144057/packages/backend/server/src/core/workspaces/resolvers/workspace.ts#L158-L194","documentation":"Thrown by the workspace(id) GraphQL query when the caller passes the Workspace.Read access assertion but models.workspace.get(id) returns null — no workspace with that id exists (deleted or never existed).","triggerScenarios":"Querying workspace(id: \"...\") with a deleted, malformed, or random id that the user happens to be allowed to assert on.","commonSituations":"Client holds a stale workspace id after deletion (page/doc bookmark), ids copied with whitespace or truncation, or scripts iterating ids that were cleaned up.","solutions":["Re-fetch the user's workspace list and use a current workspace id.","Confirm the id is the exact workspace identifier (no encoding issues, no doc id passed instead of workspace id).","If the workspace was deleted unexpectedly, check the deletion audit/records."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before deep-linking, confirm the id is in the user's workspace list\nconst list = await gql.request(GET_WORKSPACES);\nif (!list.workspaces.some(w => w.id === targetId)) {\n  router.replace('/404');\n}","typeGuard":"const isSpaceNotFound = (e: unknown): boolean =>\n  getGraphqlErrorCode(e) === 'space_not_found';","tryCatchPattern":"try {\n  const { workspace } = await gql.request(GET_WORKSPACE, { id });\n} catch (e) {\n  if (isSpaceNotFound(e)) router.replace('/404');\n}","preventionTips":["Validate workspace ids against a fresh workspace-list query before navigating or persisting them.","Drop stored workspace ids that 404 so stale references don't recur."],"tags":["workspace","graphql","not-found","query"],"backgroundTag":"resource-not-found","analyzedSha":"2af30773aecd567f09b346e7b72fc69143144057","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}