Scoop icon indicating copy to clipboard operation
Scoop copied to clipboard

Catch problems from Foreach-Object -Parallel

Open arberg opened this issue 1 year ago • 0 comments

Catch problems from Foreach-Object -Parallel and fall back to using the non-parallel safe variant. Errors will likely be output should the problem occur, but at least it will work.

See details of the problem here: https://github.com/ScoopInstaller/Scoop/issues/6126

It's not pretty but it should work according to my tests.

See

Description

I just copied the non-parallel script-block into a function. If the parallel fails, I revert to the non-parallel. I know the catch should work and actually catch something, as I have seen that in my logs when I wrapped the 'scoop update' in a try-catch.

Motivation and Context

Actually I'm unsure if this is a powershell issue or whether its scoop using it wrongly.

Closes #6126

How Has This Been Tested?

I unfortunately could not trigger the problem. So I have only tested it by checking it works, and by

and reverting my buckets running this in the buckets dir to give it something to work on

cd c:\Users\Administrator\scoop\buckets
dir  | %{push-location $_ ; git reset --hard HEAD~10; Pop-Location}

I've checked it works in powershell5 and powershell 7.4.5. I have (temporarily) added a throw "test" above the foreach -parallel, to check the fallback code in pwsh 7. This is to simulate the behaviour of pwsh I have detected in my testing from when problem occurs.

Checklist:

  • [x] I have read the Contributing Guide.
  • [x ] I have ensured that I am targeting the develop branch.
  • [x ] I have updated the documentation accordingly.
  • [x ] I have updated the tests accordingly.
  • [x ] I have added an entry in the CHANGELOG.

I don't know where to add that entry in changelog, though this would seem sensible:

  • scoop-update: Fix 'scoop update' when powershell fails in Foreach-Object -Parallel' (#6126)

arberg avatar Sep 01 '24 10:09 arberg