From 7154cda51a1aca97ec72bc6e497605a3756020e5 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Wed, 26 Feb 2025 22:57:19 -0500 Subject: [PATCH] Check if configuration is valid prior to attempting migration This means that we can make the migration step as expensive as necessary, since we will no longer run it on every app startup. --- pkg/config/app_config.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index e7d884dbb91..a09cb7368ec 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -191,15 +191,25 @@ func loadUserConfig(configFiles []*ConfigFile, base *UserConfig) (*UserConfig, e return nil, err } - content, err = migrateUserConfig(path, content) + existingCustomCommands := base.CustomCommands + + var node yaml.Node + err = yaml.Unmarshal(content, &node) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to parse config at `%s` as YAML document. Please check your file before opening an issue\n %w", path, err) } - existingCustomCommands := base.CustomCommands - - if err := yaml.Unmarshal(content, base); err != nil { - return nil, fmt.Errorf("The config at `%s` couldn't be parsed, please inspect it before opening up an issue.\n%w", path, err) + err = node.Decode(base) + if err != nil { + // We attempt to migrate the configuration, and then re-attempt to unmarshal + content, err = migrateUserConfig(path, content) + if err != nil { + return nil, err + } + err = yaml.Unmarshal(content, base) + if err != nil { + return nil, fmt.Errorf("Failed to decode config at path `%s` after attempting auto-migration. Please check your file before opening an issue\n %w", path, err) + } } base.CustomCommands = append(base.CustomCommands, existingCustomCommands...)