From 40916b852377310bbe0984f459e08c7fc3b39429 Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Wed, 23 Apr 2025 12:33:45 +0100 Subject: [PATCH] Message --- packages/gitbook-v2/src/lib/context.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/gitbook-v2/src/lib/context.ts b/packages/gitbook-v2/src/lib/context.ts index 84c6231b9..7ef0f463b 100644 --- a/packages/gitbook-v2/src/lib/context.ts +++ b/packages/gitbook-v2/src/lib/context.ts @@ -243,27 +243,37 @@ export async function fetchSiteContextByIds( ? parseSiteSectionsAndGroups(siteStructure, ids.siteSection) : null; + // Parse the current siteSpace and siteSpaces based on the site structure type. const { siteSpaces, siteSpace }: { siteSpaces: SiteSpace[]; siteSpace: SiteSpace } = (() => { if (siteStructure.type === 'siteSpaces') { const siteSpaces = siteStructure.structure; const siteSpace = siteSpaces.find((siteSpace) => siteSpace.id === ids.siteSpace); if (!siteSpace) { - throw new Error(`Site space "${ids.siteSpace}" not found in structure type="siteSpaces"`); + throw new Error( + `Site space "${ids.siteSpace}" not found in structure type="siteSpaces"` + ); } return { siteSpaces, siteSpace }; } if (siteStructure.type === 'sections') { - assert(sections, `missing parsed sections siteStructure.type="sections" siteSection="${ids.siteSection}"`); + 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); + 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}"`); + throw new Error( + `Site space "${ids.siteSpace}" not found in structure type="sections" currentSection="${currentSection.id}"` + ); } return { siteSpaces, siteSpace };