Skip to content

[Bug] getDebugLogger noop fallback silently drops events before initDebugLogger runs #412

@samzong

Description

@samzong

Problem

The module-level debugLogger in debug/index.ts is initialized to a set of noop functions that return empty DebugEvent stubs. Any code that calls getDebugLogger().error(...) (or any other level) before initDebugLogger(...) runs has its event silently dropped — no warning, no console output, nothing. Given that getDebugLogger has 50+ call sites across the main process (gateway-client, auto-updater, tray, quick-launch, workspace init, etc.), it is easy for a module-level or early-startup error to disappear without a trace, making real incidents invisible during the window that matters most (app boot).

Location

File: packages/desktop/src/main/debug/index.ts:6-15

const noop = (): DebugEvent => ({ ts: '', level: 'debug', domain: 'app', event: '' }) as DebugEvent;
let debugLogger: DebugLogger = {
  debug: noop,
  info: noop,
  warn: noop,
  error: noop,
  log: noop,
  getRecentEvents: () => [],
  currentFilePath: () => '',
};

Fix Approach

Pick one of, in order of increasing investment:

  1. Minimum: replace the noop stubs with variants that console.warn whenever called before init — noop = (input) => { console.warn('[debug] logger not initialized, dropping event:', input); return stub; }. The log won't end up in the ndjson file, but at least the developer sees it in the terminal.
  2. Better: buffer events in an in-memory queue until initDebugLogger runs, then flush the queue into the real logger. Cap the queue at a small size (e.g. 256) to prevent unbounded pre-init allocation.

Option 2 is the fully correct fix; option 1 is a one-liner that catches the common case.

Verification

  1. Run pnpm check — must pass.
  2. Unit test: call getDebugLogger().error(...) before initDebugLogger, then call init, then assert the earlier event appears in the real logger (option 2) or that a console warning was emitted (option 1).

Context

  • WG: Observability & DX
  • Priority: Low (good first issue)
  • Estimated effort: 15-30 minutes (option 1) / 1 hour (option 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/dxObservability & DX WGgood first issueGood for newcomerskind/bugCategorizes issue or PR as related to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions