Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-55617] Surface config serialization errors #570

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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