Skip to content

Commit

Permalink
fix: better error message when extracting a file that doesn't exist i…
Browse files Browse the repository at this point in the history
…n the archive
  • Loading branch information
erikian committed Oct 21, 2023
1 parent 009bf95 commit 9a26e68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ class Filesystem {
followLinks = typeof followLinks === 'undefined' ? true : followLinks
const info = this.getNode(p)

if (!info) {
throw new Error(`"${p}" was not found in this archive`)
}

// if followLinks is false we don't resolve symlinks
if (info.link && followLinks) {
return this.getFile(info.link)
Expand Down
3 changes: 3 additions & 0 deletions test/cli-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ describe('command line interface', function () {
await execAsar('e test/input/extractthis-unpack.asar tmp/extractthis-unpack-cli/')
return compDirs('tmp/extractthis-unpack-cli/', 'test/expected/extractthis')
})
it('should throw an error when trying to extract a file that doesn\'t exist in the archive', async () => {
await assert.rejects(execAsar('ef test/input/extractthis.asar this-file-doesnt-exist.404'), /"(.*?)" was not found in this archive/)
})
it('should create archive from directory with unpacked dirs', async () => {
await execAsar('p test/input/packthis/ tmp/packthis-unpack-dir-cli.asar --unpack-dir dir2 --exclude-hidden')
assert.ok(fs.existsSync('tmp/packthis-unpack-dir-cli.asar.unpacked/dir2/file2.png'))
Expand Down

0 comments on commit 9a26e68

Please sign in to comment.