Skip to content

Commit

Permalink
Surface config serialization errors (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 authored Nov 21, 2023
1 parent c6231b5 commit 8408b6e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,26 +444,31 @@ func (p *Plugin) ConfigurationWillBeSaved(newCfg *model.Config) (*model.Config,

configData := newCfg.PluginSettings.Plugins[manifest.Id]

appErr := model.NewAppError("saveConfig", "app.save_config.error", nil, "", http.StatusBadRequest)
appErr.SkipTranslation = true

js, err := json.Marshal(configData)
if err != nil {
p.LogError("failed to marshal config data", "error", err.Error())
return nil, nil
err = fmt.Errorf("failed to marshal config data: %w", err)
p.LogError(err.Error())
appErr.Message = err.Error()
return nil, appErr
}

var cfg configuration
if err := json.Unmarshal(js, &cfg); err != nil {
p.LogError("failed to unmarshal config data", "error", err.Error())
return nil, nil
err = fmt.Errorf("failed to unmarshal config data: %w", err)
p.LogError(err.Error())
appErr.Message = err.Error()
return nil, appErr
}

// Setting defaults prevents errors in case the plugin is updated after a new
// setting has been added. In this case the default value will be used.
cfg.SetDefaults()

if err := cfg.IsValid(); err != nil {
appErr := model.NewAppError("saveConfig", "app.save_config.error", nil, "", http.StatusBadRequest)
appErr.Message = err.Error()
appErr.SkipTranslation = true
return nil, appErr
}

Expand Down

0 comments on commit 8408b6e

Please sign in to comment.