Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better error message when extracting a file that doesn't exist in the archive #286

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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