From 2ad495d62f8027a7898191f2d5a85640a5fbe36f Mon Sep 17 00:00:00 2001 From: Camille Drapier Date: Fri, 2 Feb 2024 15:34:02 +0900 Subject: [PATCH] fix: Hanging indefinitely when unzip fails with an empty error --- cli/CHANGELOG.md | 6 ++++- cli/lib/tasks/unzip.js | 8 +++---- cli/test/lib/tasks/unzip_spec.js | 39 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 14396db3cfc0..6915254f86c8 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,5 +1,5 @@ -## 13.6.5 +## 13.6.5 _Released 2/13/2024 (PENDING)_ @@ -7,6 +7,10 @@ _Released 2/13/2024 (PENDING)_ - Improved accessibility of the Cypress App in some areas. Addressed in [#28774](https://github.com/cypress-io/cypress/pull/28774). +**Bugfixes:** + +- Fixed an issue with the unzip promise never being rejected when an empty error happens. Fixed in [#28850](https://github.com/cypress-io/cypress/pull/28850). + ## 13.6.4 _Released 1/30/2024_ diff --git a/cli/lib/tasks/unzip.js b/cli/lib/tasks/unzip.js index 5993bd2700a3..a4c911a5dfad 100644 --- a/cli/lib/tasks/unzip.js +++ b/cli/lib/tasks/unzip.js @@ -84,11 +84,11 @@ const unzip = ({ zipFilePath, installDir, progress }) => { return resolve() }) .catch((err) => { - if (err) { - debug('error %s', err.message) + const error = err || new Error('Unknown error with Node extract tool') - return reject(err) - } + debug('error %s', error.message) + + return reject(error) }) } diff --git a/cli/test/lib/tasks/unzip_spec.js b/cli/test/lib/tasks/unzip_spec.js index 286439f67010..af42b21fe730 100644 --- a/cli/test/lib/tasks/unzip_spec.js +++ b/cli/test/lib/tasks/unzip_spec.js @@ -132,6 +132,45 @@ describe('lib/tasks/unzip', function () { }) }) + it('can try unzip first then fall back to node unzip and fails with an empty error', async function () { + const zipFilePath = path.join('test', 'fixture', 'example.zip') + + sinon.stub(unzip.utils.unzipTools, 'extract').callsFake(() => { + return new Promise((_, reject) => reject()) + }) + + const unzipChildProcess = new events.EventEmitter() + + unzipChildProcess.stdout = { + on () {}, + } + + unzipChildProcess.stderr = { + on () {}, + } + + sinon.stub(cp, 'spawn').withArgs('unzip').returns(unzipChildProcess) + + setTimeout(() => { + debug('emitting unzip error') + unzipChildProcess.emit('error', new Error('unzip fails badly')) + }, 100) + + try { + await unzip + .start({ + zipFilePath, + installDir, + }) + } catch (err) { + logger.error(err) + expect(err.message).to.include('Unknown error with Node extract tool') + + return + } + throw new Error('should have failed') + }) + it('calls node unzip just once', function (done) { const zipFilePath = path.join('test', 'fixture', 'example.zip')