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(cli): show additional mitigation steps for max path length error #21047

Merged
merged 4 commits into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/error-messages#win-max-path-length
cowboy marked this conversation as resolved.
Show resolved Hide resolved

----------

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/error-messages#win-max-path-length`,
}

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