Skip to content

Commit

Permalink
fix(agent): continue if config upgrade fails because config does not …
Browse files Browse the repository at this point in the history
…exist
  • Loading branch information
joshuar committed Oct 6, 2023
1 parent 31561e0 commit c116a8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func newAgent(o *AgentOptions) *Agent {
}
a.ui = fyneui.NewFyneUI(a)
if err = config.UpgradeConfig(configPath); err != nil {
log.Fatal().Err(err).Msg("Could not upgrade config.")
if _, ok := err.(*config.ConfigFileNotFoundError); !ok {
log.Fatal().Err(err).Msg("Could not upgrade config.")
}
}
if a.config, err = viperconfig.New(configPath); err != nil {
log.Fatal().Err(err).Msg("Could not open config.")
Expand Down
20 changes: 17 additions & 3 deletions internal/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ type AgentConfig interface {
StoragePath(string) (string, error)
}

type ConfigFileNotFoundError struct {
Err error
}

func (e *ConfigFileNotFoundError) Error() string {
return e.Err.Error()
}

const (
websocketPath = "/api/websocket"
webHookPath = "/api/webhook/"
Expand Down Expand Up @@ -98,15 +106,21 @@ func UpgradeConfig(path string) error {
if semver.Compare(AppVersion, "v5.0.0") < 0 {
c := fyneconfig.NewFyneConfig()
if err := c.Get("Version", &configVersion); err != nil {
return errors.New("could not retrieve config version")
return &ConfigFileNotFoundError{
Err: errors.New("could not retrieve config version"),
}
}
} else {
c, err := viperconfig.New(path)
if err != nil {
return errors.New("could not open viper config")
return &ConfigFileNotFoundError{
Err: errors.New("could not open viper config"),
}
}
if err := c.Get("Version", &configVersion); err != nil {
return errors.New("could not retrieve config version")
return &ConfigFileNotFoundError{
Err: errors.New("could not retrieve config version"),
}
}
}

Expand Down

0 comments on commit c116a8d

Please sign in to comment.