From 9196022e01beb0213139ce188411b27ab1cd99e9 Mon Sep 17 00:00:00 2001 From: Piotr Srebrny Date: Fri, 1 Apr 2022 11:56:57 +0200 Subject: [PATCH] Make Copy-Item to throw exception if source does not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copy-Item command does not throw by default. Thus, copying error is not caught and the Download function returns without downloading from the official site. Adding "-errorAction stop" makes Copy-Item to throw an exception as expected in the script. Change-Id: I889cccac775705613e641453aca9e0197645f344 Reviewed-by: Simo Fält Reviewed-by: Toni Saario --- coin/provisioning/common/windows/helpers.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coin/provisioning/common/windows/helpers.ps1 b/coin/provisioning/common/windows/helpers.ps1 index 8599791d..1967b02a 100644 --- a/coin/provisioning/common/windows/helpers.ps1 +++ b/coin/provisioning/common/windows/helpers.ps1 @@ -148,7 +148,7 @@ function Download if ($CachedUrl.StartsWith("http")) { Invoke-WebRequest -UseBasicParsing $CachedUrl -OutFile $Destination } else { - Copy-Item $CachedUrl $Destination + Copy-Item $CachedUrl $Destination -errorAction stop } } catch { Write-Host "Cached download failed: Downloading from official location: $OfficialUrl"