Skip to content

Commit

Permalink
fix: Use-Git Pipeline step validation ( Fixes #312 )
Browse files Browse the repository at this point in the history
Improving inner error handling
  • Loading branch information
James Brundage committed Oct 12, 2024
1 parent 44ec857 commit 56e56ad
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Commands/Use-Git.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
$callingContext.CommandElements -join ' '
}
elseif ($myInv.Line) {
$myInv.Line.Substring($myInv.OffsetInLine - 1)
$myInv.Line.Substring($myInv.OffsetInLine - 1) -replace '\|\s{0,}$'
}

# If there's nothing to validate, there are no dynamic parameters.
Expand All @@ -106,7 +106,12 @@
# Therefore, when testing dynamic parameters, assign to a variable (because parenthesis and pipes may make this an invalid ScriptBlock)
$callingContext = try {
[scriptblock]::Create($ToValidate).Ast.EndBlock.Statements[0].PipelineElements[0]
} catch { $null}
} catch {
# If we failed to create the script block, the error is noise.
$err = $_
Write-Debug -Message "Failed to create script block from '$ToValidate' : $($err.Exception.Message)"
$Error.RemoveAt(0)
}
}
foreach ($commandElement in $callingContext.CommandElements) {
if (-not $commandElement.parameterName) { continue } # that is a Powershell parameter
Expand Down

0 comments on commit 56e56ad

Please sign in to comment.