Skip to content

refactor(config): clean up BurntSushi/toml usage in LoadFromFile#4483

Open
Copilot wants to merge 3 commits intomainfrom
copilot/go-fan-review-burntsushi-toml
Open

refactor(config): clean up BurntSushi/toml usage in LoadFromFile#4483
Copilot wants to merge 3 commits intomainfrom
copilot/go-fan-review-burntsushi-toml

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 24, 2026

Three minor cleanup items identified in a Go Fan module review of BurntSushi/toml usage in internal/config/config_core.go.

Changes

  • Remove dead code branch — both arms of the ParseError type assertion produced identical output (fmt.Errorf("failed to parse TOML: %w", ...)); collapsed to a single return
  • Fix comment accuracydecoder.Decode (the Decoder method) is what's called, not the top-level toml.Decode function
  • Improve LoadFromFile godoc — add canonical function-name prefix; document the errors.As pattern for callers that need structured parse-error details (line/column/source snippet)
// Before
if perr, ok := err.(toml.ParseError); ok {
    return nil, fmt.Errorf("failed to parse TOML: %w", perr)  // identical to the else branch
}
return nil, fmt.Errorf("failed to parse TOML: %w", err)

// After
return nil, fmt.Errorf("failed to parse TOML: %w", err)

The %w verb already preserves the concrete toml.ParseError type through the wrapping, so downstream callers can still use errors.As to extract line/column info — now documented in the godoc.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build3345233236/b509/launcher.test /tmp/go-build3345233236/b509/launcher.test -test.testlogfile=/tmp/go-build3345233236/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.9/x-p go x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build1779078529/b513/launcher.test /tmp/go-build1779078529/b513/launcher.test -test.testlogfile=/tmp/go-build1779078529/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1779078529/b497/vet.cfg pkg/mod/go.opentelemetry.io/otel@v1.43.0/semconvgo1.25.9 -trimpath .cfg -p cptest -lang=go1.17 ache/go/1.25.9/x64/pkg/tool/linux_amd64/vet -W -I /tmp/go-build3345233236/b346/ x_amd64/vet . --gdwarf2 --64 x_amd64/vet (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3345233236/b491/config.test /tmp/go-build3345233236/b491/config.test -test.testlogfile=/tmp/go-build3345233236/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true linux.go 64/src/vendor/gogoogle.golang.org/grpc/credentials x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build1779078529/b495/config.test /tmp/go-build1779078529/b495/config.test -test.testlogfile=/tmp/go-build1779078529/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s 5233�� g_.a ache/go/1.25.9/x64/src/net/http/internal/httpcommon/httpcommon.ggoogle.golang.org/grpc/internal//tmp/go-build3510073492/b354/vet.cfg docker-compose -errorsas ernal/tracing -nilfunc docker-compose -o mnvzNK45F -trimpath ache/go/1.25.9/x64/pkg/tool/linux_amd64/vet -p net/http -lang=go1.25 ortcfg (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3345233236/b509/launcher.test /tmp/go-build3345233236/b509/launcher.test -test.testlogfile=/tmp/go-build3345233236/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.9/x-p go x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build1779078529/b513/launcher.test /tmp/go-build1779078529/b513/launcher.test -test.testlogfile=/tmp/go-build1779078529/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1779078529/b497/vet.cfg pkg/mod/go.opentelemetry.io/otel@v1.43.0/semconvgo1.25.9 -trimpath .cfg -p cptest -lang=go1.17 ache/go/1.25.9/x64/pkg/tool/linux_amd64/vet -W -I /tmp/go-build3345233236/b346/ x_amd64/vet . --gdwarf2 --64 x_amd64/vet (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build3345233236/b509/launcher.test /tmp/go-build3345233236/b509/launcher.test -test.testlogfile=/tmp/go-build3345233236/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.9/x-p go x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build1779078529/b513/launcher.test /tmp/go-build1779078529/b513/launcher.test -test.testlogfile=/tmp/go-build1779078529/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1779078529/b497/vet.cfg pkg/mod/go.opentelemetry.io/otel@v1.43.0/semconvgo1.25.9 -trimpath .cfg -p cptest -lang=go1.17 ache/go/1.25.9/x64/pkg/tool/linux_amd64/vet -W -I /tmp/go-build3345233236/b346/ x_amd64/vet . --gdwarf2 --64 x_amd64/vet (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3345233236/b518/mcp.test /tmp/go-build3345233236/b518/mcp.test -test.testlogfile=/tmp/go-build3345233236/b518/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true se httptrace/trace.go x_amd64/vet -I /tmp/go-build334--version -I x_amd64/vet -I /opt/hostedtoolcache/go/1.25.9/x-errorsas .cfg x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build1779078529/b522/mcp.test /tmp/go-build1779078529/b522/mcp.test -test.testlogfile=/tmp/go-build1779078529/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s -W -I /tmp/go-build3345233236/b346/ x_amd64/vet . --gdwarf2 --64 x_amd64/vet -I /opt/hostedtoolc-s -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 24, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Review Go module BurntSushi/toml for compliance refactor(config): clean up BurntSushi/toml usage in LoadFromFile Apr 24, 2026
Copilot AI requested a review from lpcox April 24, 2026 15:26
@lpcox lpcox marked this pull request as ready for review April 24, 2026 15:52
Copilot AI review requested due to automatic review settings April 24, 2026 15:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors LoadFromFile TOML parsing to simplify BurntSushi/toml error handling and improve the surrounding documentation.

Changes:

  • Removes a dead toml.ParseError type-assertion branch (both branches wrapped the same way).
  • Corrects the parsing comment to reference decoder.Decode (not toml.Decode).
  • Expands LoadFromFile godoc, including guidance on using errors.As to extract toml.ParseError.
Show a summary per file
File Description
internal/config/config_core.go Simplifies parse-error wrapping and updates/expands LoadFromFile documentation.

Copilot's findings

Tip

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

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

Comment on lines +320 to +323
// var perr toml.ParseError
// if errors.As(err, &perr) {
// fmt.Println(perr.Position())
// }
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

Within the new godoc code blocks, some lines are indented using spaces (e.g., the fmt.Println(...) line in the errors.As snippet). Other godoc examples in the repo use tab indentation (e.g., internal/auth/header.go:24-34), which also aligns with gofmt-style formatting and consistent rendering in godoc. Consider switching these code-block indents to tabs.

Copilot uses AI. Check for mistakes.
Comment thread internal/config/config_core.go Outdated
Comment on lines +304 to +306
// LoadFromFile parses a TOML configuration file at path and returns the
// validated Config, or an error if the file cannot be opened, parsed, or
// contains unknown fields.
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The docstring summary says LoadFromFile errors only when the file can’t be opened/parsed or contains unknown fields, but the function also returns validation errors (e.g., no servers defined, containerization/auth/tracing/trusted_bots validations, etc.). Update the summary to include validation failures so callers aren’t misled about possible error cases.

Copilot uses AI. Check for mistakes.
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented Apr 24, 2026

@copilot address this review feedback #4483 (review)

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 24, 2026

@copilot address this review feedback #4483 (review)

Done in 93dd347:

  • Switched godoc code-block indentation from spaces to tabs (both the errors.As snippet and the TOML example)
  • Expanded the summary line to cover validation failures: no servers defined, containerization, auth, tracing, and trusted_bots checks

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build2488137266/b509/launcher.test /tmp/go-build2488137266/b509/launcher.test -test.testlogfile=/tmp/go-build2488137266/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 8137266/b156/_pk-p gpg.program x_amd64/compile (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build2488137266/b491/config.test /tmp/go-build2488137266/b491/config.test -test.testlogfile=/tmp/go-build2488137266/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 8137266/b214/_pk-p 64/src/vendor/gogoogle.golang.org/grpc/metadata x_amd64/compile (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build2488137266/b509/launcher.test /tmp/go-build2488137266/b509/launcher.test -test.testlogfile=/tmp/go-build2488137266/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 8137266/b156/_pk-p gpg.program x_amd64/compile (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build2488137266/b509/launcher.test /tmp/go-build2488137266/b509/launcher.test -test.testlogfile=/tmp/go-build2488137266/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 8137266/b156/_pk-p gpg.program x_amd64/compile (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build2488137266/b518/mcp.test /tmp/go-build2488137266/b518/mcp.test -test.testlogfile=/tmp/go-build2488137266/b518/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ime/protoiface/l-errorsas ime/protoiface/m-ifaceassert x_amd64/compile 8137266/b171/ crypto/internal//usr/bin/runc -lang=go1.25 x_amd64/compile -I azero@v1.11.0/internal/engine/wa-p azero@v1.11.0/internal/engine/wagolang.org/x/net/http2 x_amd64/vet -o /dev/null /tmp/ccSj0J3s.s x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

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