Adds robustness to file system operations

Improves error handling when creating directories,
loading, and saving settings. This prevents crashes and
provides more informative error messages to the user.

Adds a try-catch block to `fs.statSync` to handle cases where a
file might be deleted between `readdirSync` and `statSync`,
preventing program termination.
This commit is contained in:
AlexKucera committed 2025-09-03 23:09:36 +02:00
1 parent 742b9a14c8
commit e48af55635
2 files changed
+35 -5

No files matched your search

+10 -1
View File
@@ -305,7 +305,16 @@ export class PandocTypstConverter {
const vaultContents = fs.readdirSync(this.pandocOptions.vaultBasePath);
for (const item of vaultContents) {
const itemPath = path.join(this.pandocOptions.vaultBasePath, item);
const stat = fs.statSync(itemPath);
let stat;
try {
stat = fs.statSync(itemPath);
} catch (error) {
// File might have been deleted between readdirSync and statSync
console.warn(`Export: Unable to stat ${itemPath}:`, error.message);
continue;
}
if (stat.isDirectory() && !item.startsWith('.') && !item.startsWith('_')) {
// Check if this directory contains images
try {