-
Notifications
You must be signed in to change notification settings - Fork 19
Enable-OutputSubscriber script blocks have the potential for a stackoverflow exception #3
Copy link
Copy link
Open
Description
When inside one of the script blocks, something will be written to the console, then this is also captured. Initially it sounds reasonable but there is a danger here.
$onWriteDebugBlock={
param(
[string]$Message
)
Write-Host "[OnWriteDebug] $Message"
}
$onWriteVerboseBlock={
param(
[string]$Message
)
Write-Host "[OnWriteVerbose] $Message"
}
$onWriteErrorBlock={
param(
[string]$Message
)
Write-Host "[OnWriteError] $Message"
}
$onWriteWarningBlock={
param(
[string]$Message
)
Write-Host "[OnWriteWarning] $Message"
}
$onWriteOutputBlock={
param(
[string]$Message
)
Write-Host "[OnWriteOutput] $Message"
}
$splat=@{
OnWriteDebug=$onWriteDebugBlock
OnWriteVerbose=$onWriteVerboseBlock
OnWriteError=$onWriteErrorBlock
OnWriteOutput=$onWriteOutputBlock
OnWriteWarning=$onWriteWarningBlock
}
$outputSubscriber=Enable-OutputSubscriber @splat
Write-Error "An error message"The Write-Error "An error message" will be captured by onWriteErrorBlock and written to the host as [OnWriteError] An error message which in turn will be captured by onWriteOutputBlock and written to the host as [OnWriteError] [OnWriteError] An error message. This flow is recursive.
The danger here is not only with the error or output but also with debug. Imagine using in the OnWriteDebug block a cmdlet that outputs debug messages.
The module is very cool but have you considered this flow?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels