-
-
Notifications
You must be signed in to change notification settings - Fork 100
Closed
Description
Description:
In the current Pode implementation, the following block of code attempts to invoke Write-PodeErrorLog inside a catch block if an exception occurs:
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 {
$_ | Write-PodeErrorLog
$ctx.Server.Console.DisableTermination = $true
$ctx.Server.Console.DisableConsoleInput = $true
$ctx.Server.Console.Quiet = $true
$ctx.Server.Console.ShowDivider = $false
}However, Write-PodeErrorLog is being called before the logging subsystem is fully initialized. This creates compatibility issues with the new logging features introduced in PR [#1387](#1387).
Expected Behavior
- The console initialization logic should handle errors gracefully without invoking
Write-PodeErrorLogprematurely. - The context should be configured for non-console behavior in case of failure, without relying on logging at this stage.
Proposed Fix
A simple fix is to check if the session is running in a console and is not marked as a daemon before proceeding. Additionally, we should remove Write-PodeErrorLog from this section:
# 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
}
}Steps to Reproduce
- Start Pode in a separated pwsh in background
- An exception is trigegred in the
tryblock. - Observe that
Write-PodeErrorLogis invoked before the logging subsystem is initialized.
Additional Notes
Removing Write-PodeErrorLog from this specific section should prevent any early logging issues while ensuring the console context is handled correctly.
Metadata
Metadata
Assignees
Labels
Projects
Status
Done