You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
github.com/BurntSushi/toml is the de-facto Go TOML parser β spec-compliant, battle-tested, and the only dependency responsible for the entire TOML configuration surface of this gateway. It provides streaming decoding, structured parse errors (with source-level context), metadata introspection, and (since v1.6.0) optional strict-mode decoding. The project uses it exclusively in internal/config/config_core.go to load and validate config.toml.
toml.Key β slice-of-strings path type used in isDynamicTOMLPath
Usage pattern summary: Config is loaded once at startup through LoadFromFile. The code uses a streaming NewDecoder (good for large configs), wraps ParseError with %w to preserve its structure for errors.As callers, manually filters md.Undecoded() via isDynamicTOMLPath instead of SetStrict(true) (because the config has two map[string]interface{} dynamic sections), and uses md.IsDefined() for conditional defaults and field-precedence logic (e.g. agent_id vs deprecated api_key).
Research Findings
Version Status
The project pins v1.6.0, which is the latest released version of BurntSushi/toml. No upgrade is needed. β
Decoder.SetStrict(true): automatically rejects unknown fields (added in v1.6.0)
ParseError.ErrorWithUsage(): returns the error message plus a source-code snippet with a column pointer β far more readable than Error() alone
MetaData.Type(key): returns the raw TOML type (String, Integer, Bool, etc.) for any decoded key
MetaData.Keys(): returns all top-level keys decoded from the document
Recent Updates
v1.6.0 was the headline release that introduced SetStrict, improved duplicate detection, and TOML 1.1 drafts. The project already documents these in the package-level godoc. The codebase is fully current.
Improvement Opportunities
π Quick Wins
1. Use ParseError.ErrorWithUsage() in the startup error log
In internal/cmd/root.go (line 218), config load failures are logged as:
The fix requires only a helper in internal/config (to keep the BurntSushi/toml import confined to that package) that checks errors.As(err, &perr) and returns perr.ErrorWithUsage() when present:
// FormatConfigError returns a rich diagnostic message for TOML parse errors,// falling back to err.Error() for all other error types.funcFormatConfigError(errerror) string {
varperr toml.ParseErroriferrors.As(err, &perr) {
returnperr.ErrorWithUsage()
}
returnerr.Error()
}
This is a pure UX improvement β zero behaviour change β and directly helps operators debug malformed config.toml files.
β¨ Feature Opportunities
2. MetaData.Type() for validation error messages
MetaData.Type(key ...string) returns the raw TOML type (String, Integer, Float, Bool, Array, Hash, Date, Time, DateTime) for any key. Currently, when validation fails (e.g. port = "abc"), the error comes from Go's unmarshalling and may be cryptic. Adding type checks could yield messages like:
gateway.port: expected integer, but TOML value is a String β did you forget to remove the quotes?
This is medium effort but improves the onboarding experience significantly.
3. Eliminate isDynamicTOMLPath by typing guard_policies and guards.*.config
The isDynamicTOMLPath workaround exists because Decoder.SetStrict(true) rejects unknown keys in map[string]interface{} fields. If guard_policies and guards.*.config were replaced with typed structs (or a defined JSON schema validated separately), SetStrict(true) could be used directly, removing the manual Undecoded() loop and the isDynamicTOMLPath function entirely. This is a larger architectural change but would simplify the validation code path.
The NewDecoder approach is slightly more idiomatic when you need to call SetStrict or configure the decoder β which this code intentionally does not do. Consider switching to DecodeReader for brevity, or add a comment explaining why NewDecoder is preferred (e.g., future SetStrict readiness).
π§ General Improvements
5. Add TOML 1.1 feature tests
The package-level godoc lists three TOML 1.1 features used (multi-line inline arrays, improved duplicate detection, large float encoding), but the test suite does not directly exercise multi-line inline array syntax in config.toml-style input. Adding one or two explicit test cases for these features would guard against version regressions.
[High value / Low effort] Add config.FormatConfigError(err) helper using ParseError.ErrorWithUsage() and use it in root.go's markdown error log β immediate UX win for operators debugging bad configs.
[Medium value / Medium effort] Use MetaData.Type() to enrich field-level validation error messages.
[Low value / Low effort] Switch NewDecoder + Decode to DecodeReader, or document why NewDecoder is kept.
[Medium value / High effort] Type guard_policies and guards.*.config to enable SetStrict(true) and retire isDynamicTOMLPath.
[Low value / Low effort] Add explicit TOML 1.1 feature tests (multi-line inline arrays) to guard against version regressions.
Next Steps
Implement config.FormatConfigError (recommendation Configure as a Go CLI toolΒ #1) β straightforward and improves the on-call debugging experience.
Consider a follow-up issue for recommendation Lpcox/add difcΒ #4 (typed guard config) as a longer-term config layer cleanup.
πΉ Go Fan Report: BurntSushi/toml
Module Overview
github.com/BurntSushi/tomlis the de-facto Go TOML parser β spec-compliant, battle-tested, and the only dependency responsible for the entire TOML configuration surface of this gateway. It provides streaming decoding, structured parse errors (with source-level context), metadata introspection, and (since v1.6.0) optional strict-mode decoding. The project uses it exclusively ininternal/config/config_core.goto load and validateconfig.toml.Current Usage in gh-aw
internal/config/config_core.go,internal/config/config_core_test.go)toml.NewDecoder(file)β streaming decoder for memory efficiencydecoder.Decode(&cfg)β decodes TOML into theConfigstruct, returnsMetaDatatoml.ParseErrorβ structured error type withPosition.Line/Position.Colmd.Undecoded()β unknown-field detection (spec Β§4.3.1 enforcement)md.IsDefined(...)β conditional key-presence checks (e.g."gateway", "port")toml.Keyβ slice-of-strings path type used inisDynamicTOMLPathUsage pattern summary: Config is loaded once at startup through
LoadFromFile. The code uses a streamingNewDecoder(good for large configs), wrapsParseErrorwith%wto preserve its structure forerrors.Ascallers, manually filtersmd.Undecoded()viaisDynamicTOMLPathinstead ofSetStrict(true)(because the config has twomap[string]interface{}dynamic sections), and usesmd.IsDefined()for conditional defaults and field-precedence logic (e.g.agent_idvs deprecatedapi_key).Research Findings
Version Status
The project pins v1.6.0, which is the latest released version of BurntSushi/toml. No upgrade is needed. β
Key Features Available in v1.6.0
Decoder.SetStrict(true): automatically rejects unknown fields (added in v1.6.0)ParseError.ErrorWithUsage(): returns the error message plus a source-code snippet with a column pointer β far more readable thanError()aloneMetaData.Type(key): returns the raw TOML type (String,Integer,Bool, etc.) for any decoded keyMetaData.Keys(): returns all top-level keys decoded from the documentRecent Updates
v1.6.0 was the headline release that introduced
SetStrict, improved duplicate detection, and TOML 1.1 drafts. The project already documents these in the package-level godoc. The codebase is fully current.Improvement Opportunities
π Quick Wins
1. Use
ParseError.ErrorWithUsage()in the startup error logIn
internal/cmd/root.go(line 218), config load failures are logged as:err.Error()on a wrappedtoml.ParseErrorproduces the compact one-liner:ParseError.ErrorWithUsage()produces a source-context-rich diagnostic:The fix requires only a helper in
internal/config(to keep theBurntSushi/tomlimport confined to that package) that checkserrors.As(err, &perr)and returnsperr.ErrorWithUsage()when present:Then in
root.go:This is a pure UX improvement β zero behaviour change β and directly helps operators debug malformed
config.tomlfiles.β¨ Feature Opportunities
2.
MetaData.Type()for validation error messagesMetaData.Type(key ...string)returns the raw TOML type (String,Integer,Float,Bool,Array,Hash,Date,Time,DateTime) for any key. Currently, when validation fails (e.g.port = "abc"), the error comes from Go's unmarshalling and may be cryptic. Adding type checks could yield messages like:This is medium effort but improves the onboarding experience significantly.
3. Eliminate
isDynamicTOMLPathby typingguard_policiesandguards.*.configThe
isDynamicTOMLPathworkaround exists becauseDecoder.SetStrict(true)rejects unknown keys inmap[string]interface{}fields. Ifguard_policiesandguards.*.configwere replaced with typed structs (or a defined JSON schema validated separately),SetStrict(true)could be used directly, removing the manualUndecoded()loop and theisDynamicTOMLPathfunction entirely. This is a larger architectural change but would simplify the validation code path.π Best Practice Alignment
4.
toml.DecodeReadershorthand (minor)The current idiom:
is functionally identical to:
The
NewDecoderapproach is slightly more idiomatic when you need to callSetStrictor configure the decoder β which this code intentionally does not do. Consider switching toDecodeReaderfor brevity, or add a comment explaining whyNewDecoderis preferred (e.g., futureSetStrictreadiness).π§ General Improvements
5. Add TOML 1.1 feature tests
The package-level godoc lists three TOML 1.1 features used (multi-line inline arrays, improved duplicate detection, large float encoding), but the test suite does not directly exercise multi-line inline array syntax in
config.toml-style input. Adding one or two explicit test cases for these features would guard against version regressions.Module Summary
github.com/BurntSushi/tomlv1.6.0internal/config/config_core.goKey Features
NewDecoder) for large filesParseError)ErrorWithUsage()Undecoded(),IsDefined(),Type(),Keys()SetStrict(true)(v1.6.0+)toml.NewEncoder) for TOML outputReferences
Recommendations
config.FormatConfigError(err)helper usingParseError.ErrorWithUsage()and use it inroot.go's markdown error log β immediate UX win for operators debugging bad configs.MetaData.Type()to enrich field-level validation error messages.NewDecoder+DecodetoDecodeReader, or document whyNewDecoderis kept.guard_policiesandguards.*.configto enableSetStrict(true)and retireisDynamicTOMLPath.Next Steps
config.FormatConfigError(recommendation Configure as a Go CLI toolΒ #1) β straightforward and improves the on-call debugging experience.Generated by Go Fan πΉ β Β§28575098781