Skip to content

Commit

Permalink
enhance(build): handle missing BLOG_ROOT + log rg errors (#9340)
Browse files Browse the repository at this point in the history
The blogs repo is not public so `BLOG_ROOT` environment variable 
has not been advertised. If the variable is not set then `yarn tool spas` 
command throws an error which doesn't make sense at all.

Co-authored-by: Claas Augner <[email protected]>
  • Loading branch information
OnkarRuikar and caugner authored Jul 20, 2023
1 parent 810edfa commit dab1fd9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ export function makeTOC(doc) {
}

export function findPostFileBySlug(slug: string): string | null {
if (!BLOG_ROOT) {
console.warn("'BLOG_ROOT' not set in .env file");
return null;
}

try {
const { stdout, stderr, status } = spawnSync(rgPath, [
"-il",
Expand All @@ -320,8 +325,12 @@ export function findPostFileBySlug(slug: string): string | null {
if (status === 0) {
const file = stdout.toString("utf-8").split("\n")[0];
return file;
}
const message = stderr.toString();
if (message) {
console.error(`error running rg: ${message}`);
} else {
console.error(`error running rg: ${stderr}`);
console.error(`Post ${slug} not found in ${BLOG_ROOT}`);
}
} catch {
console.error("rg failed");
Expand Down

0 comments on commit dab1fd9

Please sign in to comment.