pkg/config: fix line numbers shown incorrectly for TOML type mismatch errors (#5195)

This commit is contained in:
fatedier
2026-03-04 20:53:22 +08:00
committed by GitHub
parent 774478d071
commit b7435967b0
2 changed files with 20 additions and 10 deletions

View File

@@ -496,7 +496,7 @@ serverPort: 7000
require.Equal(7000, clientCfg.ServerPort)
}
func TestTOMLSyntaxErrorWithLineNumber(t *testing.T) {
func TestTOMLSyntaxErrorWithPosition(t *testing.T) {
require := require.New(t)
// TOML with syntax error (unclosed table array header)
@@ -510,8 +510,9 @@ name = "test"
clientCfg := v1.ClientConfig{}
err := LoadConfigure([]byte(content), &clientCfg, false, "toml")
require.Error(err)
require.Contains(err.Error(), "line")
require.Contains(err.Error(), "toml")
require.Contains(err.Error(), "line")
require.Contains(err.Error(), "column")
}
func TestTOMLTypeMismatchErrorWithFieldInfo(t *testing.T) {
@@ -529,6 +530,7 @@ proxies = "this should be a table array"
// The error should contain field info
errMsg := err.Error()
require.Contains(errMsg, "proxies")
require.NotContains(errMsg, "line")
}
func TestFindFieldLineInContent(t *testing.T) {