Skip to content

config: use ParseError.ErrorWithUsage() for richer TOML startup diagnostics#8505

Merged
lpcox merged 3 commits into
mainfrom
copilot/go-fan-review-burntsushi-toml
Jul 2, 2026
Merged

config: use ParseError.ErrorWithUsage() for richer TOML startup diagnostics#8505
lpcox merged 3 commits into
mainfrom
copilot/go-fan-review-burntsushi-toml

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

When config.toml fails to parse, the startup log only showed the terse one-liner from err.Error(). toml.ParseError.ErrorWithUsage() (available since BurntSushi/toml v1.6.0) produces a source-context-rich diagnostic with a file snippet and column pointer — significantly better for on-call debugging.

Changes

  • internal/config/config_core.go — adds exported FormatConfigError(err error) string that unwraps toml.ParseError via errors.As and returns ErrorWithUsage(), falling back to err.Error() for all other error types. Keeps the BurntSushi/toml import confined to the config package.

  • internal/cmd/root.go — replaces err.Error() with config.FormatConfigError(err) in the LogErrorToMarkdown call on config load failure.

  • internal/config/config_core_test.go — three subtests: TOML parse error produces |/^ source annotations, plain error falls back correctly, wrapped non-TOML error falls back correctly.

Before:

Configuration validation failed:
failed to parse TOML: toml: line 5 (field command): expected "=", got "[" instead

After:

Configuration validation failed:
toml: line 5 (field command): expected "=", got "[" instead

  3 | [servers.github]
  4 | command = "docker"
  5 | [servers.github
      | ^

Copilot AI linked an issue Jul 2, 2026 that may be closed by this pull request
GitHub Advanced Security started work on behalf of lpcox July 2, 2026 22:31 View session
GitHub Advanced Security finished work on behalf of lpcox July 2, 2026 22:31
Copilot AI changed the title [WIP] Review Go module BurntSushi/toml usage config: use ParseError.ErrorWithUsage() for richer TOML startup diagnostics Jul 2, 2026
Copilot finished work on behalf of lpcox July 2, 2026 22:37
Copilot AI requested a review from lpcox July 2, 2026 22:37
@lpcox lpcox marked this pull request as ready for review July 2, 2026 22:42
Copilot AI review requested due to automatic review settings July 2, 2026 22:42
GitHub Advanced Security started work on behalf of lpcox July 2, 2026 22:43 View session
GitHub Advanced Security finished work on behalf of lpcox July 2, 2026 22:43

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 improves startup diagnostics when config.toml fails to parse by emitting BurntSushi/toml’s source-context-rich ParseError.ErrorWithUsage() output instead of the plain err.Error(), making on-call debugging significantly easier.

Changes:

  • Added config.FormatConfigError(err error) string to unwrap TOML toml.ParseError and return ErrorWithUsage() when applicable.
  • Updated startup error logging in internal/cmd/root.go to use config.FormatConfigError(err).
  • Added unit tests covering TOML parse errors vs non-TOML error fallbacks.
Show a summary per file
File Description
internal/config/config_core.go Adds FormatConfigError helper to format TOML parse errors with source context.
internal/cmd/root.go Uses FormatConfigError when logging config load failures during startup.
internal/config/config_core_test.go Adds tests verifying FormatConfigError behavior across TOML and non-TOML errors.

Review details

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread internal/config/config_core.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

[go-fan] Go Module Review: BurntSushi/toml

3 participants