Skip to content

Commit

Permalink
Fix #4048 Gracefully fail mkdirSync
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Nov 2, 2023
1 parent cae6524 commit faf2de3
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/components/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,21 +677,26 @@ export class Builder {
outDir = path.resolve(rootDir, outDir)
}
logger.log(`outDir: ${outDir} .`)
try {
lw.cacher.getIncludedTeX(rootFile).forEach(file => {
const relativePath = path.dirname(file.replace(rootDir, '.'))
const fullOutDir = path.resolve(outDir, relativePath)
// To avoid issues when fullOutDir is the root dir
// Using fs.mkdir() on the root directory even with recursion will result in an error
lw.cacher.getIncludedTeX(rootFile).forEach(file => {
const relativePath = path.dirname(file.replace(rootDir, '.'))
const fullOutDir = path.resolve(outDir, relativePath)
// To avoid issues when fullOutDir is the root dir
// Using fs.mkdir() on the root directory even with recursion will result in an error
try {
if (! (fs.existsSync(fullOutDir) && fs.statSync(fullOutDir).isDirectory())) {
fs.mkdirSync(fullOutDir, { recursive: true })
}
})
} catch (e) {
logger.log('Unexpected Error: please see the console log of the Developer Tools of VS Code.')
logger.refreshStatus('x', 'errorForeground')
throw(e)
}
} catch (e) {
if (e instanceof Error) {
// #4048
logger.log(`Unexpected Error: ${e.name}: ${e.message} .`)
} else {
logger.log('Unexpected Error: please see the console log of the Developer Tools of VS Code.')
logger.refreshStatus('x', 'errorForeground')
throw(e)
}
}
})
}
}

Expand Down

0 comments on commit faf2de3

Please sign in to comment.