From 5000d6cab2bbfc0b2aae59a07ee863d6aaa61154 Mon Sep 17 00:00:00 2001 From: Freddy Kristiansen Date: Fri, 26 Jan 2024 14:49:28 +0100 Subject: [PATCH] Give better error message if GitHub CLI or GIT isn't installed (#898) Fixes #870 --------- Co-authored-by: freddydk --- Actions/AL-Go-Helper.ps1 | 2 +- ...ReferenceDocumentation.HelperFunctions.ps1 | 2 +- Actions/Github-Helper.psm1 | 24 +++++++++++++++---- RELEASENOTES.md | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Actions/AL-Go-Helper.ps1 b/Actions/AL-Go-Helper.ps1 index 6b4fc4dc1..2c4d596de 100644 --- a/Actions/AL-Go-Helper.ps1 +++ b/Actions/AL-Go-Helper.ps1 @@ -2261,7 +2261,7 @@ function RetryCommand { catch { $retryCount++ if ($retryCount -eq $MaxRetries) { - throw $_ + throw } else { Write-Host "Retrying after $RetryDelaySeconds seconds..." diff --git a/Actions/BuildReferenceDocumentation/BuildReferenceDocumentation.HelperFunctions.ps1 b/Actions/BuildReferenceDocumentation/BuildReferenceDocumentation.HelperFunctions.ps1 index 2b398d95f..b88a25129 100644 --- a/Actions/BuildReferenceDocumentation/BuildReferenceDocumentation.HelperFunctions.ps1 +++ b/Actions/BuildReferenceDocumentation/BuildReferenceDocumentation.HelperFunctions.ps1 @@ -24,7 +24,7 @@ & /usr/bin/env sudo pwsh -command "& chmod +x $ENV:aldocPath" } Write-Host "Installing/Updating docfx" - CmdDo -command dotnet -arguments @("tool","update","-g docfx") + CmdDo -command dotnet -arguments @("tool","update","-g docfx") -messageIfCmdNotFound "dotnet not found. Please install it from https://dotnet.microsoft.com/download" } return $ENV:aldocPath } diff --git a/Actions/Github-Helper.psm1 b/Actions/Github-Helper.psm1 index a3209c85a..633dff752 100644 --- a/Actions/Github-Helper.psm1 +++ b/Actions/Github-Helper.psm1 @@ -237,7 +237,8 @@ function CmdDo { [string] $arguments = "", [switch] $silent, [switch] $returnValue, - [string] $inputStr = "" + [string] $inputStr = "", + [string] $messageIfCmdNotFound = "" ) $oldNoColor = "$env:NO_COLOR" @@ -282,14 +283,27 @@ function CmdDo { Write-Host $message } if ($returnValue) { - $message.Replace("`r","").Split("`n") + $message.Replace("`r", "").Split("`n") } } else { - $message += "`n`nExitCode: "+$p.ExitCode + "`nCommandline: $command $arguments" + $message += "`n`nExitCode: " + $p.ExitCode + "`nCommandline: $command $arguments" throw $message } } + catch [System.ComponentModel.Win32Exception] { + if ($_.Exception.NativeErrorCode -eq 2) { + if ($messageIfCmdNotFound) { + throw $messageIfCmdNotFound + } + else { + throw "Command $command not found, you might need to install that command." + } + } + else { + throw + } + } finally { try { [Console]::OutputEncoding = $oldEncoding } catch {} $env:NO_COLOR = $oldNoColor @@ -319,7 +333,7 @@ function invoke-gh { $arguments += "$parameter " } } - cmdDo -command gh -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr + cmdDo -command gh -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr -messageIfCmdNotFound "Github CLI not found. Please install it from https://cli.github.com/" } } @@ -343,7 +357,7 @@ function invoke-git { $arguments += "$parameter " } } - cmdDo -command git -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr + cmdDo -command git -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr -messageIfCmdNotFound "Git not found. Please install it from https://git-scm.com/downloads" } } diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a7412b2a4..232e65cf7 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -7,6 +7,7 @@ Note that when using the preview version of AL-Go for GitHub, we recommend you U ### Issues - Support release branches that start with releases/ +- Issue 870 Improve Error Handling when CLI is missing ### Build modes AL-Go ships with Default, Translated and Clean mode out of the box. Now you can also define custom build modes in addition to the ones shipped with AL-Go. This allows you to define your own build modes, which can be used to build your apps in different ways. By default, a custom build mode will build the apps similarly to the Default mode but this behavior can be overridden in e.g. script overrides in your repository.