From ce738690e6387f6bccc185df8f155ef4107923f1 Mon Sep 17 00:00:00 2001 From: Frode Flaten <3436158+fflaten@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:27:05 +0000 Subject: [PATCH] Improve error message for unbound scriptblock input to clarify potential issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Jareš --- src/Pester.Runtime.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pester.Runtime.ps1 b/src/Pester.Runtime.ps1 index c73d0bacb..40ef93a56 100644 --- a/src/Pester.Runtime.ps1 +++ b/src/Pester.Runtime.ps1 @@ -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'") } }