Skip to content

Commit

Permalink
fix(cli): show additional mitigation steps for max path length error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Apr 14, 2022
1 parent 57dbc17 commit 546ed16
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 25 deletions.
1 change: 1 addition & 0 deletions cli/__snapshots__/errors_spec.js
Expand Up @@ -32,6 +32,7 @@ exports['errors individual has the following errors 1'] = [
"childProcessKilled",
"failedDownload",
"failedUnzip",
"failedUnzipWindowsMaxPathLength",
"incompatibleHeadlessFlags",
"invalidCacheDirectory",
"invalidCypressEnv",
Expand Down
20 changes: 19 additions & 1 deletion cli/__snapshots__/unzip_spec.js
@@ -1,4 +1,4 @@
exports['unzip error 1'] = `
exports['lib/tasks/unzip throws when cannot unzip 1'] = `
Error: The Cypress App could not be unzipped.
Search for an existing issue or open a GitHub issue at
Expand All @@ -15,3 +15,21 @@ Platform: darwin-x64 (Foo-OsVersion)
Cypress Version: 1.2.3
`

exports['lib/tasks/unzip throws max path length error when cannot unzip due to realpath ENOENT on windows 1'] = `
Error: The Cypress App could not be unzipped.
This is most likely because the maximum path length is being exceeded on your system.
Read here for solutions to this problem: https://on.cypress.io/win-max-path-length-error
----------
Error: failed
----------
Platform: win32-x64 (Foo-OsVersion)
Cypress Version: 1.2.3
`
8 changes: 8 additions & 0 deletions cli/lib/errors.js
Expand Up @@ -58,6 +58,13 @@ const failedUnzip = {
solution: genericErrorSolution,
}

const failedUnzipWindowsMaxPathLength = {
description: 'The Cypress App could not be unzipped.',
solution: `This is most likely because the maximum path length is being exceeded on your system.
Read here for solutions to this problem: https://on.cypress.io/win-max-path-length-error`,
}

const missingApp = (binaryDir) => {
return {
description: `No version of Cypress is installed in: ${chalk.cyan(
Expand Down Expand Up @@ -404,6 +411,7 @@ module.exports = {
unexpected,
failedDownload,
failedUnzip,
failedUnzipWindowsMaxPathLength,
invalidCypressEnv,
invalidCacheDirectory,
CYPRESS_RUN_BINARY,
Expand Down
29 changes: 19 additions & 10 deletions cli/lib/tasks/unzip.js
Expand Up @@ -195,26 +195,35 @@ const unzip = ({ zipFilePath, installDir, progress }) => {
})
}

const start = ({ zipFilePath, installDir, progress }) => {
function isMaybeWindowsMaxPathLengthError (err) {
return os.platform() === 'win32' && err.code === 'ENOENT' && err.syscall === 'realpath'
}

const start = async ({ zipFilePath, installDir, progress }) => {
la(is.unemptyString(installDir), 'missing installDir')
if (!progress) {
progress = { onProgress: () => {
return {}
} }
}

return fs.pathExists(installDir)
.then((exists) => {
if (exists) {
try {
const installDirExists = await fs.pathExists(installDir)

if (installDirExists) {
debug('removing existing unzipped binary', installDir)

return fs.removeAsync(installDir)
await fs.removeAsync(installDir)
}
})
.then(() => {
return unzip({ zipFilePath, installDir, progress })
})
.catch(throwFormErrorText(errors.failedUnzip))

await unzip({ zipFilePath, installDir, progress })
} catch (err) {
const errorTemplate = isMaybeWindowsMaxPathLengthError(err) ?
errors.failedUnzipWindowsMaxPathLength
: errors.failedUnzip

await throwFormErrorText(errorTemplate)(err)
}
}

module.exports = {
Expand Down
46 changes: 32 additions & 14 deletions cli/test/lib/tasks/unzip_spec.js
Expand Up @@ -30,26 +30,44 @@ describe('lib/tasks/unzip', function () {

afterEach(function () {
stdout.restore()
})

it('throws when cannot unzip', async function () {
try {
await unzip.start({
zipFilePath: path.join('test', 'fixture', 'bad_example.zip'),
installDir,
})
} catch (err) {
logger.error(err)

// return fs.removeAsync(installationDir)
return snapshot(normalize(this.stdout.toString()))
}

throw new Error('should have failed')
})

it('throws when cannot unzip', function () {
const ctx = this
it('throws max path length error when cannot unzip due to realpath ENOENT on windows', async function () {
const err = new Error('failed')

return unzip
.start({
zipFilePath: path.join('test', 'fixture', 'bad_example.zip'),
installDir,
})
.then(() => {
throw new Error('should have failed')
})
.catch((err) => {
err.code = 'ENOENT'
err.syscall = 'realpath'

os.platform.returns('win32')
sinon.stub(fs, 'ensureDirAsync').rejects(err)

try {
await unzip.start({
zipFilePath: path.join('test', 'fixture', 'bad_example.zip'),
installDir,
})
} catch (err) {
logger.error(err)

snapshot('unzip error 1', normalize(ctx.stdout.toString()))
})
return snapshot(normalize(this.stdout.toString()))
}

throw new Error('should have failed')
})

it('can really unzip', function () {
Expand Down

3 comments on commit 546ed16

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 546ed16 Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.5/linux-x64/develop-546ed16c77f44727d5b09e1e7197182e1bd41de9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 546ed16 Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.5/darwin-x64/develop-546ed16c77f44727d5b09e1e7197182e1bd41de9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 546ed16 Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.5/win32-x64/develop-546ed16c77f44727d5b09e1e7197182e1bd41de9/cypress.tgz

Please sign in to comment.