Skip to content

Commit dd5de4c

Browse files
Don't give up when unable to extract some files (#244)
* Don't give up when unable to extract some files Add try/catch block around file extraction so that the rest of the files are extracted if there is an issue with only a subset of the files in the archive. * Fix unmatched curly brace Added a closing curly brace because I'd missed one out * removed a semicolon that was upsetting the linter * Throw AggregateError if file couldn't be extracted Collect file extraction errors and throw AggregateError after every file extraction has been attempted * Removed logging & fixed extractionErrors handling ...as suggested by Samuel Attard * Remove dependancy on AggregateError
1 parent f60a4c1 commit dd5de4c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/asar.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ module.exports.extractAll = function (archive, dest) {
180180
// create destination directory
181181
fs.mkdirpSync(dest)
182182

183+
const extractionErrors = []
183184
for (const fullPath of filenames) {
184185
// Remove leading slash
185186
const filename = fullPath.substr(1)
@@ -200,14 +201,23 @@ module.exports.extractAll = function (archive, dest) {
200201
const linkTo = path.join(relativePath, path.basename(file.link))
201202
fs.symlinkSync(linkTo, destFilename)
202203
} else {
203-
// it's a file, extract it
204-
const content = disk.readFileSync(filesystem, filename, file)
205-
fs.writeFileSync(destFilename, content)
206-
if (file.executable) {
207-
fs.chmodSync(destFilename, '755')
204+
// it's a file, try to extract it
205+
try {
206+
const content = disk.readFileSync(filesystem, filename, file)
207+
fs.writeFileSync(destFilename, content)
208+
if (file.executable) {
209+
fs.chmodSync(destFilename, '755')
210+
}
211+
} catch (e) {
212+
extractionErrors.push(e)
208213
}
209214
}
210215
}
216+
if (extractionErrors.length) {
217+
throw new Error(
218+
'Unable to extract some files:\n\n' +
219+
extractionErrors.map(error => error.stack).join('\n\n'))
220+
}
211221
}
212222

213223
module.exports.uncache = function (archive) {

0 commit comments

Comments
 (0)