Skip to content

Commit 871e0fc

Browse files
committed
don't swallow all errors from access()
1 parent 8bf9f4b commit 871e0fc

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/mdx.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,11 @@ export async function getFileBySlug(slug: string) {
349349
let configFrontmatter: PlatformConfig | undefined;
350350
try {
351351
configFrontmatter = yaml.load(await readFile(configPath, 'utf8')) as PlatformConfig;
352-
} catch (e) {
352+
} catch (err) {
353353
// If the config file does not exist, we can ignore it.
354+
if (err.code !== 'ENOENT') {
355+
throw err;
356+
}
354357
}
355358

356359
let mdxPath = path.join(root, `${slug}.mdx`);
@@ -391,8 +394,11 @@ export async function getFileBySlug(slug: string) {
391394
mdPath = path.join(root, `${commonFilePath}.md`);
392395
mdIndexPath = path.join(root, commonFilePath, 'index.md');
393396
versionedMdxIndexPath = getVersionedIndexPath(root, commonFilePath, '.mdx');
394-
} catch {
397+
} catch (err) {
395398
// If the common folder does not exist, we can ignore it.
399+
if (err.code !== 'ENOENT') {
400+
throw err;
401+
}
396402
}
397403
}
398404
}
@@ -402,8 +408,11 @@ export async function getFileBySlug(slug: string) {
402408
try {
403409
await access(mdxIndexPath);
404410
mdxIndexPath = addVersionToFilePath(mdxIndexPath, slug.split(VERSION_INDICATOR)[1]);
405-
} catch {
411+
} catch (err) {
406412
// pass, the file does not exist
413+
if (err.code !== 'ENOENT') {
414+
throw err;
415+
}
407416
}
408417
}
409418

@@ -432,11 +441,11 @@ export async function getFileBySlug(slug: string) {
432441
try {
433442
const cached = JSON.parse(await readFile(cacheFile, 'utf8'));
434443
return cached;
435-
} catch (e) {
436-
if (e.code !== 'ENOENT') {
444+
} catch (err) {
445+
if (err.code !== 'ENOENT') {
437446
// If cache is corrupted, ignore and proceed
438447
// eslint-disable-next-line no-console
439-
console.warn(`Failed to read MDX cache: ${cacheFile}`, e);
448+
console.warn(`Failed to read MDX cache: ${cacheFile}`, err);
440449
}
441450
}
442451

0 commit comments

Comments
 (0)