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:
2 files changed
+35
-5
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user