GitbookIO/gitbook · error · Error
Site space "${ids.siteSpace}" not found in structure type="s
Error message
Site space "${ids.siteSpace}" not found in structure type="sections" currentSection="${currentSection.id}" What it means
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.
Source
Thrown at packages/gitbook/src/lib/context.ts:367
}
return { siteSpaces, siteSpace, visibleSiteSpaces: filterHiddenSiteSpaces(siteSpaces) };
}
if (siteStructure.type === 'sections') {
assert(
sections,
`cannot find site space "${ids.siteSpace}" because parsed sections are missing siteStructure.type="sections" siteSection="${ids.siteSection}"`
);
const currentSection = sections.current;
const siteSpaces = currentSection.siteSpaces;
const siteSpace = currentSection.siteSpaces.find(
(siteSpace) => siteSpace.id === ids.siteSpace
);
if (!siteSpace) {
throw new Error(
`Site space "${ids.siteSpace}" not found in structure type="sections" currentSection="${currentSection.id}"`
);
}
return {
siteSpaces,
siteSpace,
visibleSiteSpaces: filterHiddenSiteSpaces(siteSpaces),
};
}
// @ts-expect-error
assertNever(siteStructure, `cannot handle site structure of type ${siteStructure.type}`);
})();
const customization = (() => {
if (ids.siteSpace) {
const siteSpaceSettings = customizations.siteSpaces[ids.siteSpace];View on GitHub (pinned to db67585ee2)
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
Example fix
// before
const ctx = await fetchSiteContextByIds(siteData, ids);
// after
try {
const ctx = await fetchSiteContextByIds(siteData, ids);
} catch (e) {
if (e instanceof Error && e.message.includes('not found in structure type="sections"')) {
notFound();
}
throw e;
} Defensive patterns
Strategy: validation
Validate before calling
const section = sections.find((s) => s.id === ids.section); const exists = section?.siteSpaces.some((s) => s.id === ids.siteSpace) ?? false;
Type guard
function siteSpaceInSection(section: Section, siteSpaceId?: string): boolean {
return section.siteSpaces.some((s) => s.id === siteSpaceId);
} Try / catch
try {
const ctx = await fetchSiteContextByIds(siteData, ids);
} catch (e) {
if (e instanceof Error && e.message.includes('type="sections"')) notFound();
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Site space "${ids.siteSpace}" not found in structure type="s
- Site space "${siteSpace.id}" not found in site structure
AI-assisted analysis of GitbookIO/gitbook@db67585ee2 (2026-08-28).
Data as JSON: /api/errors/7e6f1ada27e2f3d8.
Report an issue: GitHub.