From a9d737026ac159458a18ed261321e14751aff382 Mon Sep 17 00:00:00 2001 From: Claas Augner <495429+caugner@users.noreply.github.com> Date: Mon, 29 May 2023 10:51:44 +0200 Subject: [PATCH] fix(kumascript): mention path in render error message (v2) (#8953) * fix(kumascript): mention path in render error message * fix(kumascript): render without fileInfo.path * fix(blog): add fileInfo.path to render context --- build/blog.ts | 9 +++++++++ kumascript/index.ts | 1 + kumascript/src/templates.ts | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/build/blog.ts b/build/blog.ts index dcbac287bc70..ea62c87362bc 100644 --- a/build/blog.ts +++ b/build/blog.ts @@ -75,6 +75,9 @@ export async function findPostLiveSampleBySlug( rawBody: body, metadata: { locale: DEFAULT_LOCALE, ...blogMeta }, isMarkdown: true, + fileInfo: { + path: file, + }, }); return liveSamples.find((page) => page.id.toLowerCase() === id)?.html; } @@ -94,6 +97,9 @@ export async function findPostBySlug( rawBody: body, metadata: { locale: DEFAULT_LOCALE, ...blogMeta }, isMarkdown: true, + fileInfo: { + path: file, + }, }); return { doc, blogMeta }; } @@ -177,6 +183,9 @@ export async function buildBlogPosts(options: { rawBody: body, metadata: { locale, ...blogMeta }, isMarkdown: true, + fileInfo: { + path: file, + }, }; const { doc: builtDoc, liveSamples } = await buildPost(renderDoc); const { doc } = { diff --git a/kumascript/index.ts b/kumascript/index.ts index f10c7e52b5db..d00c3ea07e0c 100644 --- a/kumascript/index.ts +++ b/kumascript/index.ts @@ -91,6 +91,7 @@ export async function render( rawHTML, { ...metadata, + path: fileInfo?.path, url, tags: metadata.tags || [], selective_mode, diff --git a/kumascript/src/templates.ts b/kumascript/src/templates.ts index 30169b343391..1cd129e64047 100644 --- a/kumascript/src/templates.ts +++ b/kumascript/src/templates.ts @@ -108,7 +108,12 @@ export default class Templates { }); return rendered.trim(); } catch (error) { - console.error(`${name} macro failed:`, error); + console.error( + `The ${name} macro in ${ + args.env.path ?? args.env.url + } failed to render.`, + error + ); throw error; } }