Skip to content

Commit b9f5c8a

Browse files
authored
fix: better error message when extracting a file that doesn't exist in the archive (#286)
1 parent 4dee8cf commit b9f5c8a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/filesystem.js

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ class Filesystem {
142142
followLinks = typeof followLinks === 'undefined' ? true : followLinks
143143
const info = this.getNode(p)
144144

145+
if (!info) {
146+
throw new Error(`"${p}" was not found in this archive`)
147+
}
148+
145149
// if followLinks is false we don't resolve symlinks
146150
if (info.link && followLinks) {
147151
return this.getFile(info.link)

test/cli-spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ describe('command line interface', function () {
8383
await execAsar('e test/input/extractthis-unpack.asar tmp/extractthis-unpack-cli/')
8484
return compDirs('tmp/extractthis-unpack-cli/', 'test/expected/extractthis')
8585
})
86+
it('should throw an error when trying to extract a file that doesn\'t exist in the archive', async () => {
87+
await assert.rejects(execAsar('ef test/input/extractthis.asar this-file-doesnt-exist.404'), /"(.*?)" was not found in this archive/)
88+
})
8689
it('should create archive from directory with unpacked dirs', async () => {
8790
await execAsar('p test/input/packthis/ tmp/packthis-unpack-dir-cli.asar --unpack-dir dir2 --exclude-hidden')
8891
assert.ok(fs.existsSync('tmp/packthis-unpack-dir-cli.asar.unpacked/dir2/file2.png'))

0 commit comments

Comments
 (0)