config: use ParseError.ErrorWithUsage() for richer TOML startup diagnostics#8505
Merged
Conversation
Copilot
AI
changed the title
[WIP] Review Go module BurntSushi/toml usage
config: use ParseError.ErrorWithUsage() for richer TOML startup diagnostics
Jul 2, 2026
Contributor
There was a problem hiding this comment.
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) stringto unwrap TOMLtoml.ParseErrorand returnErrorWithUsage()when applicable. - Updated startup error logging in
internal/cmd/root.goto useconfig.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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
config.tomlfails to parse, the startup log only showed the terse one-liner fromerr.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 exportedFormatConfigError(err error) stringthat unwrapstoml.ParseErrorviaerrors.Asand returnsErrorWithUsage(), falling back toerr.Error()for all other error types. Keeps theBurntSushi/tomlimport confined to theconfigpackage.internal/cmd/root.go— replaceserr.Error()withconfig.FormatConfigError(err)in theLogErrorToMarkdowncall 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:
After: