Skip to content

Commit 119a15c

Browse files
author
James Brundage
committed
Invoke-PipeScript: Terminating Transpiler Errors (#161)
1 parent f5fe735 commit 119a15c

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Invoke-PipeScript.ps1

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127

128128

129129
# If the command is a ```[ScriptBlock]```
130-
if ($Command -is [scriptblock])
130+
if ($Command -is [scriptblock])
131131
{
132132
# Attempt to transpile it.
133133
$TranspiledScriptBlock = $Command | .>Pipescript @ErrorsAndWarnings
@@ -142,8 +142,28 @@
142142
})
143143
return
144144
}
145+
146+
if ($TranspilerErrors) {
147+
$failedMessage = @(
148+
"$($command.Source): " + "$($TranspilerErrors.Count) error(s)"
149+
if ($transpilerWarnings) {
150+
"$($TranspilerWarnings.Count) warning(s)"
151+
}
152+
) -join ','
153+
Write-Error $failedMessage -ErrorId Build.Failed -TargetObject (
154+
[PSCustomObject][ordered]@{
155+
Output = $pipescriptOutput
156+
Errors = $TranspilerErrors
157+
Warnings = $TranspilerWarnings
158+
Command = $Command
159+
Parameters = $InvokePipeScriptParameters
160+
}
161+
)
162+
}
163+
145164
# If it could not be transpiled into a [ScriptBlock] or [ScriptBlock[]]
146-
if ($transpiledScriptBlock -isnot [ScriptBlock] -and -not ($TranspiledScriptBlock -as [scriptblock[]])) {
165+
if ($TranspilerErrors -or
166+
($transpiledScriptBlock -isnot [ScriptBlock] -and -not ($TranspiledScriptBlock -as [scriptblock[]]))) {
147167
# error out.
148168
Write-Error "Command {$command} could not be transpiled into [ScriptBlock]s"
149169
return

0 commit comments

Comments
 (0)