@@ -198,14 +198,20 @@ try {
198198 ' CONTINUE' { }
199199 ' SILENTLYCONTINUE' { }
200200 default {
201- Write-Error (Get-VstsLocString - Key ' PS_InvalidErrorActionPreference' - ArgumentList $input_errorActionPreference )
201+ Write-VstsTaskError (Get-VstsLocString - Key ' PS_InvalidErrorActionPreference' - ArgumentList $input_errorActionPreference )
202202 }
203203 }
204204
205205 $input_failOnStderr = Get-VstsInput - Name ' failOnStderr' - AsBool
206206 $input_ignoreLASTEXITCODE = Get-VstsInput - Name ' ignoreLASTEXITCODE' - AsBool
207207 $input_workingDirectory = Get-VstsInput - Name ' workingDirectory' - Require
208- Assert-VstsPath - LiteralPath $input_workingDirectory - PathType ' Container'
208+ try {
209+ Assert-VstsPath - LiteralPath $input_workingDirectory - PathType ' Container'
210+ }
211+ catch {
212+ Write-VstsTaskError (Get-VstsLocString - Key ' PS_InvalidWorkingDirectory' - ArgumentList $input_workingDirectory )
213+ throw $_
214+ }
209215
210216 $scriptType = Get-VstsInput - Name ' scriptType' - Require
211217 $input_arguments = Get-VstsInput - Name ' arguments'
@@ -216,11 +222,11 @@ try {
216222 Assert-VstsPath - LiteralPath $input_filePath - PathType Leaf
217223 }
218224 catch {
219- Write-Error (Get-VstsLocString - Key ' PS_InvalidFilePath' - ArgumentList $input_filePath )
225+ Write-VstsTaskError (Get-VstsLocString - Key ' PS_InvalidFilePath' - ArgumentList $input_filePath )
220226 }
221227
222228 if (! $input_filePath.ToUpperInvariant ().EndsWith(' .PS1' )) {
223- Write-Error (Get-VstsLocString - Key ' PS_InvalidFilePath' - ArgumentList $input_filePath )
229+ Write-VstsTaskError (Get-VstsLocString - Key ' PS_InvalidFilePath' - ArgumentList $input_filePath )
224230 }
225231 }
226232 else {
@@ -365,8 +371,12 @@ try {
365371}
366372finally {
367373 if ($scriptType -And " $scriptType " .ToUpperInvariant() -eq " INLINE" ) {
368- Write-Host " Cleaning up temporary script file $input_filePath "
369- Remove-Item - Path $input_filePath - Force
374+ if ($input_filePath -And (Test-Path - Path $input_filePath )) {
375+ Write-Host " Cleaning up temporary script file $input_filePath "
376+ Remove-Item - Path $input_filePath - Force
377+ } else {
378+ Write-Host " Temporary script file does not exist, nothing to clean: $input_filePath "
379+ }
370380 }
371381
372382 Trace-VstsLeavingInvocation $MyInvocation
0 commit comments