Skip to content

Commit

Permalink
fix: Suppress filesystem errors during glob search (#25774)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-plummer authored Feb 13, 2023
1 parent 748f3a5 commit 2c35510
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ _Released 02/14/2023 (PENDING)_
- Fixed an issue in middleware where error-handling code could itself generate an error and fail to report the original issue. Fixes [#22825](https://github.com/cypress-io/cypress/issues/22825).
- Fixed an issue that could cause the Debug page to display a different number of specs for in-progress runs than shown in Cypress Cloud. Fixes [#25647](https://github.com/cypress-io/cypress/issues/25647).
- Fixed an issue introduced in Cypress 12.3.0 where custom browsers that relied on process environment variables were not found on macOS arm64 architectures. Fixed in [#25753](https://github.com/cypress-io/cypress/pull/25753).
- Fixed an issue where Cypress would fail to load any specs if the project `specPattern` included a resource that could not be accessed due to filesystem permissions. Fixes [#24109](https://github.com/cypress-io/cypress/issues/24109).

**Misc:**

Expand Down
14 changes: 11 additions & 3 deletions packages/data-context/src/sources/FileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class FileDataSource {
return this.ctx.fs.readFile(path.join(this.ctx.currentProject, relative), 'utf-8')
}

async getFilesByGlob (cwd: string, glob: string | string[], globOptions?: GlobbyOptions) {
async getFilesByGlob (cwd: string, glob: string | string[], globOptions: GlobbyOptions = {}): Promise<string[]> {
const globs = ([] as string[]).concat(glob).map((globPattern) => {
const workingDirectoryPrefix = path.join(cwd, path.sep)

Expand All @@ -49,7 +49,7 @@ export class FileDataSource {
return globPattern
})

const ignoreGlob = (globOptions?.ignore ?? []).concat('**/node_modules/**')
const ignoreGlob = (globOptions.ignore ?? []).concat('**/node_modules/**')

if (os.platform() === 'win32') {
// globby can't work with backwards slashes
Expand All @@ -72,7 +72,15 @@ export class FileDataSource {

return files
} catch (e) {
debug('error in getFilesByGlob %o', e)
if (!globOptions.suppressErrors) {
// Log error and retry with filesystem errors suppressed - this allows us to find partial
// results even if the glob search hits permission issues (#24109)
debug('Error in getFilesByGlob %o, retrying with filesystem errors suppressed', e)

return await this.getFilesByGlob(cwd, glob, { ...globOptions, suppressErrors: true })
}

debug('Non-suppressible error in getFilesByGlob %o', e)

return []
}
Expand Down
29 changes: 29 additions & 0 deletions packages/data-context/test/unit/sources/FileDataSource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,35 @@ describe('FileDataSource', () => {
},
)
})

it('should retry search with `suppressErrors` if non-suppressed attempt fails', async () => {
matchGlobsStub.onFirstCall().rejects(new Error('mocked filesystem error'))
matchGlobsStub.onSecondCall().resolves(mockMatches)

const files = await fileDataSource.getFilesByGlob(
'/',
'/cypress/e2e/**.cy.js',
{ absolute: false, objectMode: true },
)

expect(files).to.eq(mockMatches)
expect(matchGlobsStub).to.have.callCount(2)
expect(matchGlobsStub.getCall(0).args[1].suppressErrors).to.be.undefined
expect(matchGlobsStub.getCall(1).args[1].suppressErrors).to.equal(true)
})

it('should return empty array if retry with suppression fails', async () => {
matchGlobsStub.rejects(new Error('mocked filesystem error'))

const files = await fileDataSource.getFilesByGlob(
'/',
'/cypress/e2e/**.cy.js',
{ absolute: false, objectMode: true },
)

expect(files).to.eql([])
expect(matchGlobsStub).to.have.callCount(2)
})
})
})
})

5 comments on commit 2c35510

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 2c35510 Feb 13, 2023

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/linux-arm64/develop-2c355109383a4b570216a0e60e3ab26d328da29c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 2c35510 Feb 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/linux-x64/develop-2c355109383a4b570216a0e60e3ab26d328da29c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 2c35510 Feb 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/darwin-x64/develop-2c355109383a4b570216a0e60e3ab26d328da29c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 2c35510 Feb 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/win32-x64/develop-2c355109383a4b570216a0e60e3ab26d328da29c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 2c35510 Feb 13, 2023

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/darwin-arm64/develop-2c355109383a4b570216a0e60e3ab26d328da29c/cypress.tgz

Please sign in to comment.