cypress: On cypress run, error "We failed to trash the existing run results"

Current behavior:

Running cypress run emits an error:

Warning: We failed to trash the existing run results.

This error will not alter the exit code.

Error: Command failed: /Users/jennifer/Library/Caches/Cypress/3.1.2/Cypress.app/Contents/Resources/app/packages/server/node_modules/trash/lib/macos-trash /Users/jennifer/Dev/cypress-example-kitchensink/cypress/screenshots/examples
“examples” couldn’t be moved to the trash.

    at ChildProcess.exithandler (child_process.js:282:12)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at maybeClose (internal/child_process.js:921:16)
    at Socket.stream.socket.on (internal/child_process.js:348:11)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at Pipe._handle.close [as _onclose] (net.js:549:12)

Desired behavior:

Not error when trashing folders within videos folder.

Steps to reproduce:

All I did was cypress run on a previous run cypress-example-kitchensink project. Of course on subsequent runs of of cypress run do not produce the same error. 😞

Versions

Cypress 3.1.2 Mac High Sierra

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 22
  • Comments: 35 (7 by maintainers)

Most upvoted comments

It seems the problem only happens when a snapshot is open by an application somewhere else while cypress is trying to clean the directory, so it can’t. At least that’s seems how I fixed it, by closing the app that still viewing the snapshot images.

Hope it helps

Still there …

image

Still exists in 10.9.0

thanks @ruvengam . My solution was, delete the video and screenshot files then cypress run again. It works.

Noticed for some reason the videos and screenshots folders were owned by root (MacOs).

I was able to workaround this by changing the ownership of the folders:

sudo chown -R $(whoami) cypress/videos
sudo chown -R $(whoami) cypress/screenshots

Encountered the same issue on version 3.4.0 on windows 10 OS, When using npx cypress run got this error:

Warning: We failed to trash the existing run results.

This error will not alter the exit code.

Error: Command failed: C:\Users\reuve-ga\AppData\Local\Cypress\Cache\3.4.0\Cypress\resources\app\packages\server\node_modules\trash\lib\win-trash.exe C:\cypress\videos\

    at ChildProcess.exithandler (child_process.js:287:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

This error followed by additional error message at one specific test:

Warning: We failed to record the video.

This error will not alter the exit code.

Error: ffmpeg exited with code 1: C:\cypress\videos\some-test\test-video.mp4: Permission denied

    at ChildProcess.<anonymous> (C:\Users\reuve-ga\AppData\Local\Cypress\Cache\3.4.0\Cypress\resources\app\packages\server\node_modules\fluent-ffmpeg\lib\processor.js:182:22)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)

{ Error: ffmpeg exited with code 1: C:\cypress\videos\some-test\test-video.mp4: Permission denied

    at ChildProcess.<anonymous> (C:\Users\reuve-ga\AppData\Local\Cypress\Cache\3.4.0\Cypress\resources\app\packages\server\node_modules\fluent-ffmpeg\lib\processor.js:182:22)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
 recordingVideoFailed: true }
Error: ffmpeg exited with code 1: C:\cypress\videos\some-test\test-video.mp4: Permission denied

    at ChildProcess.<anonymous> (C:\Users\reuve-ga\AppData\Local\Cypress\Cache\3.4.0\Cypress\resources\app\packages\server\node_modules\fluent-ffmpeg\lib\processor.js:182:22)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)

Reading the permission denied comment in the error message I ran Cypress with admin privileges, This didn’t help to resolve the issue. Only then I started looking for the same issue in Cypress github project, found this issue, as @adamchenwei mentioned I found that the video specified in the second warning is open in a media player app.

It looks like Cypress failed to trash the video folder since it was in use by the media player, So it issued the first warning: Warning: We failed to trash the existing run results.

Then when cypress tried to override the video opened in the media player it got the We failed to record the video with Permission denied.

This don`t look like a bug, this is the OS preventing modification of an open file. But Cypress warning message can suggest looking for the specified file in open programs.

When I specify "screenshotsFolder": false in cypress.json, this error also occurs.

It happens because the screenshot has nested folders The following commands help me:

PowerShell

give write access to the folder:

icacls "cypress\cypress\screenshots\FOLDER_NAME" /grant:r "$env:USERNAME`:F" /T

Remove the read-only attribute (-R), removes the archive attribute (-A) to the folder

attrib -R -A "cypress\cypress\screenshots\FOLDER_NAME"

change FOLDER_NAME to your folders name

or for multiple nested folders:

Get-ChildItem -Path "cypress\cypress\screenshots" -Directory -Recurse | foreach { attrib -R -A "$($_.FullName)\*" /S }
Get-ChildItem -Path "cypress\cypress\screenshots" -Directory -Recurse | foreach { icacls $_.FullName /grant:r "$env:USERNAME`:F" /T }

Hello,

Still exists in 12.4.0. So I manage to update macos-trash directly in the cypress.app package.

Download the binary from https://github.com/sindresorhus/macos-trash Extract it and rename from trash to macos-trash

Need to chown (setting the right group) : open a terminal and change to your download directory

chown :staff macos-trash

Browse to the directory (adapt your own path)

cd /Users/xxx/Library/Caches/Cypress/12.4.0/Cypress.app/Contents/Resources/app/node_modules/trash/lib

Keep a copy for the original

cp macos-trash macos-trash-original cp ~/Downloads/macos-trash .

The file was already mark as executable If needed :

chmod +x macos-trash

Now, no more error, the directory is cleaned normally.

Best

John

same issue with Windows 10 and Cypress 4.10.0

Warning: We failed to trash the existing run results.

This error will not alter the exit code.

Error: Command failed: C:\Users\user\AppData\Local\Cypress\Cache\4.10.0\Cypress\resources\app\packages\server\node_modules\trash\lib\win-trash.exe C:\dev\cypress\media\tests.ts.mp4