Skip to content

Clarify logger fallback contract and add direct fallback-handler coverage#6590

Merged
lpcox merged 6 commits into
mainfrom
copilot/duplicate-code-fallback-error-handler
May 27, 2026
Merged

Clarify logger fallback contract and add direct fallback-handler coverage#6590
lpcox merged 6 commits into
mainfrom
copilot/duplicate-code-fallback-error-handler

Conversation

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor

The logger package already centralizes initialization through initLogger, but the fallback handlers for file, markdown, and tools loggers shared the same degraded-mode contract without documenting it explicitly. This change makes that contract explicit and adds direct coverage for the concrete handlers so fallback semantics do not drift.

  • Fallback contract

    • Document loggerErrorHandlerFunc as the boundary for degraded-mode behavior:
      • fallback-capable handlers return a logger with useFallback=true and nil error
      • strict handlers return the initialization error
    • Clarify the per-logger fallback modes in initLogger docs, including ToolsLogger
  • Focused handler coverage

    • Add direct tests for:
      • handleFileLoggerError
      • handleMarkdownLoggerError
      • handleToolsLoggerError
    • Assert each handler returns a usable degraded logger with the expected fallback state instead of relying only on filesystem-failure tests
  • Example

    // Fallback-capable handlers return degraded mode, not hard failure.
    logger, err := handleMarkdownLoggerError(assert.AnError, "/tmp/logs", "test.md")
    require.NoError(t, err)
    assert.True(t, logger.useFallback)

Copilot AI changed the title [WIP] Refactor duplicate logger fallback error handlers Clarify logger fallback contract and add direct fallback-handler coverage May 27, 2026
Copilot finished work on behalf of lpcox May 27, 2026 15:10
Copilot AI requested a review from lpcox May 27, 2026 15:10
@lpcox lpcox marked this pull request as ready for review May 27, 2026 15:21
Copilot AI review requested due to automatic review settings May 27, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR documents the “degraded mode” contract for logger initialization error handlers (fallback vs. strict behavior) and adds focused unit tests to ensure the concrete fallback handlers continue to return usable loggers with the expected fallback state.

Changes:

  • Document loggerErrorHandlerFunc contract: fallback-capable handlers return (logger(useFallback=true), nil), strict handlers return an error.
  • Clarify initLogger docs for per-logger fallback modes (including ToolsLogger).
  • Add direct unit tests for handleFileLoggerError, handleMarkdownLoggerError, and handleToolsLoggerError.
Show a summary per file
File Description
internal/logger/fallback_handlers_test.go Adds direct tests asserting fallback handlers return degraded loggers with useFallback=true.
internal/logger/common.go Documents the fallback/strict contract and clarifies initLogger fallback semantics per logger type.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment thread internal/logger/fallback_handlers_test.go Outdated
Comment thread internal/logger/fallback_handlers_test.go Outdated
Comment thread internal/logger/fallback_handlers_test.go Outdated
lpcox and others added 3 commits May 27, 2026 08:33
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit bff2f17 into main May 27, 2026
21 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-fallback-error-handler branch May 27, 2026 15:40
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.

[duplicate-code] Duplicate Code Pattern: Logger Fallback Error Handler Boilerplate

3 participants