Skip to content

cerbero: Return an error when download fails on powershell

Nirbheek Chauhan requested to merge nirbheek/cerbero:pwsh-download-error into main

The &{ } construct we were using for chaining commands actually eats the exit code of the last command. Turns out we don't actually need that construct at all to chain commands.

Tested as:

C:\>powershell -Command "&{ Set-Variable -Name ProgressPreference -Value 'SilentlyContinue'; Invoke-WebRequest -UserAgent GStreamerCerbero/1.21.2.1 -OutFile pango-1.50.11.tar.xz -Method Get -Uri https://do
wnload.gnome.org/sources/pango/1.50/pango-1.50.91.tar.xz }"
Invoke-WebRequest : <html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.22.1</center>
</body>
</html>
At line:1 char:69
+ ... yContinue'; Invoke-WebRequest -UserAgent GStreamerCerbero/1.21.2.1 -O ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

C:\>echo %ErrorLevel%
0
C:\>powershell -Command Set-Variable -Name ProgressPreference -Value 'SilentlyContinue'; Invoke-WebRequest -UserAgent GStreamerCerbero/1.21.2.1 -OutFile pango-1.50.11.tar.xz -Method Get -Uri https://downlo
ad.gnome.org/sources/pango/1.50/pango-1.50.91.tar.xz
Invoke-WebRequest : <html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.22.1</center>
</body>
</html>
At line:1 char:66
+ ... yContinue'; Invoke-WebRequest -UserAgent GStreamerCerbero/1.21.2.1 -O ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

C:\>echo %ErrorLevel%
1

C:\>powershell -Command "Set-Variable -Name ProgressPreference -Value 'SilentlyContinue'; Invoke-WebRequest -UserAgent GStreamerCerbero/1.21.2.1 -OutFile pango-1.50.11.tar.xz -Method Get -Uri https://downl
oad.gnome.org/sources/pango/1.50/pango-1.50.11.tar.xz"

C:\>echo %ErrorLevel%
0
Edited by Nirbheek Chauhan

Merge request reports