From cd2b3cea8acab270ea4f18823c0a905192a14e94 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 11 Feb 2026 18:19:39 +0100 Subject: [PATCH] List valid versions in unsupported config version error Assisted-By: cagent --- pkg/config/config.go | 6 ++++-- pkg/config/validation_test.go | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 6d573ce4a..91e603f63 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "log/slog" + "maps" "net/url" "slices" "strings" @@ -73,9 +74,10 @@ func CheckRequiredEnvVars(ctx context.Context, cfg *latest.Config, modelsGateway } func parseCurrentVersion(data []byte, version string) (any, error) { - parser, found := Parsers()[version] + parsers := Parsers() + parser, found := parsers[version] if !found { - return nil, fmt.Errorf("unsupported config version: %v", version) + return nil, fmt.Errorf("unsupported config version: %v (valid versions: %s)", version, strings.Join(slices.Sorted(maps.Keys(parsers)), ", ")) } return parser(data) } diff --git a/pkg/config/validation_test.go b/pkg/config/validation_test.go index 6de1983e4..fe5e409e1 100644 --- a/pkg/config/validation_test.go +++ b/pkg/config/validation_test.go @@ -4,6 +4,7 @@ import ( "path/filepath" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -71,6 +72,23 @@ func TestValidationErrors(t *testing.T) { } } +func TestLoadConfig_UnsupportedVersion(t *testing.T) { + t.Parallel() + + cfg := `version: "99" +agents: + root: + model: openai/gpt-4 +` + _, err := Load(t.Context(), NewBytesSource("test", []byte(cfg))) + require.Error(t, err) + assert.Contains(t, err.Error(), "unsupported config version: 99") + assert.Contains(t, err.Error(), "valid versions") + // Check that at least some known versions are listed + assert.Contains(t, err.Error(), "1") + assert.Contains(t, err.Error(), "2") +} + func TestValidSkillsConfiguration(t *testing.T) { t.Parallel()