Skip to content

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

Merged
Badgerati merged 3 commits intoBadgerati:developfrom
mdaneri:issue-1514
Mar 18, 2025
Merged

Fix: Prevent Early Invocation of Write-PodeErrorLog in Console Setup#1515
Badgerati merged 3 commits intoBadgerati:developfrom
mdaneri:issue-1514

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.

@Badgerati Badgerati added bug 🐛 story-points: 1 Minimal effort. Simple bug fixes, minor docs, or quick config tweaks. Little to no review needed labels Mar 16, 2025
@Badgerati Badgerati added this to the 2.12.1 milestone Mar 16, 2025
@Badgerati Badgerati merged commit 47cb891 into Badgerati:develop Mar 18, 2025
14 checks passed
@mdaneri mdaneri deleted the issue-1514 branch March 18, 2025 13:19
@Badgerati Badgerati mentioned this pull request Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 story-points: 1 Minimal effort. Simple bug fixes, minor docs, or quick config tweaks. Little to no review needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write-PodeErrorLog` Called Before Log Subsystem Initialization in Console Setup

2 participants