{"record":{"id":"7e6f1ada27e2f3d8","repo":"GitbookIO/gitbook","slug":"site-space-ids-sitespace-not-found-in-structu-7e6f1a","errorCode":null,"errorMessage":"Site space \"${ids.siteSpace}\" not found in structure type=\"sections\" currentSection=\"${currentSection.id}\"","messagePattern":"Site space \"(.+?)\" not found in structure type=\"sections\" currentSection=\"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gitbook/src/lib/context.ts","lineNumber":367,"sourceCode":"            }\n\n            return { siteSpaces, siteSpace, visibleSiteSpaces: filterHiddenSiteSpaces(siteSpaces) };\n        }\n\n        if (siteStructure.type === 'sections') {\n            assert(\n                sections,\n                `cannot find site space \"${ids.siteSpace}\" because parsed sections are missing siteStructure.type=\"sections\" siteSection=\"${ids.siteSection}\"`\n            );\n\n            const currentSection = sections.current;\n            const siteSpaces = currentSection.siteSpaces;\n            const siteSpace = currentSection.siteSpaces.find(\n                (siteSpace) => siteSpace.id === ids.siteSpace\n            );\n\n            if (!siteSpace) {\n                throw new Error(\n                    `Site space \"${ids.siteSpace}\" not found in structure type=\"sections\" currentSection=\"${currentSection.id}\"`\n                );\n            }\n\n            return {\n                siteSpaces,\n                siteSpace,\n                visibleSiteSpaces: filterHiddenSiteSpaces(siteSpaces),\n            };\n        }\n\n        // @ts-expect-error\n        assertNever(siteStructure, `cannot handle site structure of type ${siteStructure.type}`);\n    })();\n\n    const customization = (() => {\n        if (ids.siteSpace) {\n            const siteSpaceSettings = customizations.siteSpaces[ids.siteSpace];","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/GitbookIO/gitbook/blob/db67585ee243d063c459a855988f21612cea9c95/packages/gitbook/src/lib/context.ts#L349-L385","documentation":"Thrown by fetchSiteContextByIds when the site structure is section-based (type 'sections') and the requested siteSpace ID is not among the current section's siteSpaces. The message also includes currentSection.id, telling you which section was being searched. It is the sections-variant of the site-space-not-found 404.","triggerScenarios":"Resolving a URL whose siteSpace segment does not exist inside the section that the URL's section segment resolved to — e.g. a URL like /s/<site>/<section>/<siteSpace> where that section has no such site space, or a space that was moved to another section.","commonSituations":"Reorganization moved a site space into a different section while old URLs/redirects still point at the old section path; section slug changes invalidating cached URLs; multi-section sites where the same space name exists in several sections but IDs were mixed up.","solutions":["Use the currentSection id from the message to inspect that section's siteSpaces and confirm where the space actually lives","If the space moved sections, redirect to the canonical URL or re-resolve by space ID instead of by path","Re-check section/space slugs in the incoming URL for typos or encoding issues","Treat as a 404 in your error boundary and render a not-found page rather than crashing the request"],"exampleFix":"// before\nconst ctx = await fetchSiteContextByIds(siteData, ids);\n\n// after\ntry {\n    const ctx = await fetchSiteContextByIds(siteData, ids);\n} catch (e) {\n    if (e instanceof Error && e.message.includes('not found in structure type=\"sections\"')) {\n        notFound();\n    }\n    throw e;\n}","handlingStrategy":"validation","validationCode":"const section = sections.find((s) => s.id === ids.section);\nconst exists = section?.siteSpaces.some((s) => s.id === ids.siteSpace) ?? false;","typeGuard":"function siteSpaceInSection(section: Section, siteSpaceId?: string): boolean {\n    return section.siteSpaces.some((s) => s.id === siteSpaceId);\n}","tryCatchPattern":"try {\n    const ctx = await fetchSiteContextByIds(siteData, ids);\n} catch (e) {\n    if (e instanceof Error && e.message.includes('type=\"sections\"')) notFound();\n    throw e;\n}","preventionTips":["When reorganizing sections, add redirects for moved site spaces","Canonicalize URLs by space ID before rendering so stale section paths are normalized","Log the currentSection id from the error to quickly locate drift"],"tags":["site-structure","sections","site-space","not-found","routing"],"backgroundTag":"resource-not-found","analyzedSha":"db67585ee243d063c459a855988f21612cea9c95","analyzedAt":"2026-08-28T17:49:47.831Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}