Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable-OutputSubscriber script blocks have the potential for a stackoverflow exception #3

Open
Sarafian opened this issue Jun 13, 2017 · 0 comments

Comments

@Sarafian
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant