Skip to content

Commit

Permalink
Improve error message for unbound scriptblock input to clarify potent…
Browse files Browse the repository at this point in the history
…ial issues

Co-authored-by: Jakub Jareš <[email protected]>
  • Loading branch information
fflaten and nohwnd committed Oct 15, 2024
1 parent 308e451 commit ce73869
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Pester.Runtime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2619,9 +2619,9 @@ function Assert-BoundScriptBlockInput {
$maxLength = 250
$prettySb = (Format-Nicely2 $ScriptBlock) -replace '\s{2,}', ' '
if ($prettySb.Length -gt $maxLength) {
$prettySb = $prettySb.Remove($maxLength) + "..."
$prettySb = "$($prettySb.Remove($maxLength))..."
}

throw [System.ArgumentException]::new("Unbound scriptblock '$prettySb' is not allowed. See https://github.com/pester/Pester/issues/2411.")
throw [System.ArgumentException]::new("Unbound scriptblock is not allowed, because it would run inside of Pester session state and produce unexpected results. See https://github.com/pester/Pester/issues/2411 for more details and workarounds. ScriptBlock: '$prettySb'")
}
}

0 comments on commit ce73869

Please sign in to comment.