Skip to content

fix: suppress duplicate error output before logging setup#236

Merged
zanjonke merged 1 commit into
mainfrom
fix/dry-run
Jul 1, 2026
Merged

fix: suppress duplicate error output before logging setup#236
zanjonke merged 1 commit into
mainfrom
fix/dry-run

Conversation

@zanjonke

@zanjonke zanjonke commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Following #214, the linked-resource validation error (e.g. Plain syntax error: Link ... does not exist.) was printed twice during --dry-run — once in plain white text, then again in red.

Root cause

console.error() in plain2code_console.py both logs the message (logger.error(...)) and rich-prints it in red. On --dry-run (and --status, --full-plain, and early parse errors), the module is parsed before setup_logging() configures any handlers. With no handler attached to the codeplain logger, Python's logging.lastResort handler echoes the logger.error(...) record to stderr as plain white text — so the same message appears twice (white from lastResort, red from rich).

Fix

Attach a NullHandler to the codeplain logger at import time (the standard Python library idiom). This suppresses lastResort so records emitted before real handlers exist aren't echoed to stderr, leaving exactly one output on these pre-logging CLI paths. Once setup_logging() runs, the real handlers work as before.

This also fixes the same latent double-print for any other pre-logging console.error/console.warning call (--status, --full-plain).

@zanjonke zanjonke requested a review from pedjaradenkovic July 1, 2026 11:48
@zanjonke zanjonke self-assigned this Jul 1, 2026
@zanjonke zanjonke added the bug Something isn't working label Jul 1, 2026
@zanjonke zanjonke merged commit 8c783f1 into main Jul 1, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants