Skip to content

Commit

Permalink
fix(kumascript): mention path in render error message (v2) (#8953)
Browse files Browse the repository at this point in the history
* fix(kumascript): mention path in render error message

* fix(kumascript): render without fileInfo.path

* fix(blog): add fileInfo.path to render context
  • Loading branch information
caugner authored May 29, 2023
1 parent 0896970 commit a9d7370
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions build/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -94,6 +97,9 @@ export async function findPostBySlug(
rawBody: body,
metadata: { locale: DEFAULT_LOCALE, ...blogMeta },
isMarkdown: true,
fileInfo: {
path: file,
},
});
return { doc, blogMeta };
}
Expand Down Expand Up @@ -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 } = {
Expand Down
1 change: 1 addition & 0 deletions kumascript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export async function render(
rawHTML,
{
...metadata,
path: fileInfo?.path,
url,
tags: metadata.tags || [],
selective_mode,
Expand Down
7 changes: 6 additions & 1 deletion kumascript/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit a9d7370

Please sign in to comment.