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

Fix: Prevent Early Invocation of Write-PodeErrorLog in Console Setup #1515

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

mdaneri
Copy link
Contributor

@mdaneri mdaneri commented Mar 4, 2025

Issue Description

This pull request implements #1514

Currently, Pode attempts to invoke Write-PodeErrorLog inside a catch block during console setup:

catch {
    $_ | Write-PodeErrorLog
    $ctx.Server.Console.DisableTermination = $true
    $ctx.Server.Console.DisableConsoleInput = $true
    $ctx.Server.Console.Quiet = $true
    $ctx.Server.Console.ShowDivider = $false
}

However, this occurs before the logging subsystem is fully initialized, leading to potential issues with the new logging features introduced in #1387

Proposed Fix

  • Added a check to ensure the session is running in a console-like environment and is not marked as a daemon before proceeding.
  • Removed the invocation of Write-PodeErrorLog from this section to avoid premature logging.

Updated Code

# Check if the current session is running in a console-like environment and it's not marked as Daemon
if (Test-PodeHasConsole -and ! $Daemon) {
    try {
        if (! (Test-PodeIsISEHost)) {
            if (!$ctx.Server.Console.Quiet) {
                [System.Console]::CursorVisible = $false

                if ($ctx.Server.Console.ShowDivider) {
                    [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
                }
            }
            if (Test-PodeIsConsoleHost) {
                [Console]::TreatControlCAsInput = $true
            }
        }
    }
    catch {
        $ctx.Server.Console.DisableTermination = $true
        $ctx.Server.Console.DisableConsoleInput = $true
        $ctx.Server.Console.Quiet = $true
        $ctx.Server.Console.ShowDivider = $false
    }
}

Justification

Testing

  • Verified that Pode initializes correctly without triggering premature logging errors.
  • Confirmed that the console behavior remains consistent after an exception.

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

Successfully merging this pull request may close these issues.

1 participant