From c7f1b946545b6e221a9b38c31195a379d110fec7 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 17 Aug 2024 13:51:10 +0200 Subject: [PATCH] Emit errors concerning WSL commands --- scripts/Common/Scripts/Config.ps1 | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index f028ea2a..c72bb5eb 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -37,7 +37,13 @@ $null = New-Module { wsl -e printf "%q" "$result"; }; - Receive-Job -Wait $job; + $result = Receive-Job -Wait $job; + + if ($job.State -ne ([System.Management.Automation.JobState]::Completed)) { + Write-Error "An error occurred while converting ``$Path`` to a Linux path.`nOutput: ``$result``"; + } + + $result; } <# @@ -87,11 +93,17 @@ $null = New-Module { wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish -- $args } - fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script" | ConvertFrom-Json; - } + $output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script"; - if (-not $?) { - throw "The configuration could not be retrieved!"; + if (-not $?) { + Write-Error "The configuration could not be retrieved!"; + } else { + if (-not ($output -and ($output | Test-Json))) { + Write-Error "The value ``$output`` is not valid JSON."; + } else { + $output | ConvertFrom-Json; + } + } } }