From 18abc9e4998e5577b4d9b13db1981d0ceacfd2ef Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 21 Aug 2024 14:08:26 +0200 Subject: [PATCH] Prevent unnecessary errors during WSL execution --- scripts/Common/Scripts/Config.ps1 | 45 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index 613e8eca..60fca018 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -30,33 +30,36 @@ $null = New-Module { [string] $Path ) - $completed = $false; + & { + $ErrorActionPreference = 'Continue'; + $completed = $false; - while (-not $completed) { - $job = Start-Job { - $env:Value = Resolve-Path $Using:Path; - $env:WSLENV = "Value/p"; - $result = wsl -- bash -c 'echo "$Value"'; - wsl -e printf "%q" "$result"; - }; + while (-not $completed) { + $job = Start-Job { + $env:Value = Resolve-Path $Using:Path; + $env:WSLENV = "Value/p"; + $result = wsl -- bash -c 'echo "$Value"'; + wsl -e printf "%q" "$result"; + }; - $result = Receive-Job -Wait $job; + $result = Receive-Job -Wait $job; - if ((Split-Path -Leaf $Path) -ne (Split-Path -Leaf $result)) { - Write-Error "The result of the path conversion of ``$Path`` was unexpected: ``$result``"; - continue; + if ((Split-Path -Leaf $Path) -ne (Split-Path -Leaf $result)) { + Write-Error "The result of the path conversion of ``$Path`` was unexpected: ``$result``"; + continue; + } + + if ($job.State -ne ([System.Management.Automation.JobState]::Completed)) { + Write-Error "An error occurred while converting ``$Path`` to a Linux path.`nOutput: ``$result``"; + continue; + } + + $completed = $true; } - if ($job.State -ne ([System.Management.Automation.JobState]::Completed)) { - Write-Error "An error occurred while converting ``$Path`` to a Linux path.`nOutput: ``$result``"; - continue; - } - - $completed = $true; - } - - $result; + $result; + }; } <#