Skip to content

Commit

Permalink
feat: enhance settings handling with improved logging and data valida…
Browse files Browse the repository at this point in the history
…tion

- Added detailed logging for debugging during settings updates and JSON unmarshaling.
- Implemented cleanup of Actions data to ensure Parameters are properly initialized.
- Enhanced error handling with more informative log messages for better traceability.
  • Loading branch information
tphakala committed Jan 9, 2025
1 parent 79ee4b5 commit ea40e1c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/httpcontroller/handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func (h *Handlers) SaveSettings(c echo.Context) error {

// Update settings from form parameters
if err := updateSettingsFromForm(settings, formParams); err != nil {
// Return an error if updating settings from form parameters fails
// Add more detailed logging for debugging
log.Printf("Debug: Form parameters for species config: %+v", formParams["realtime.species.config"])
return h.NewHandlerError(err, "Error updating settings", http.StatusInternalServerError)
}

Expand Down Expand Up @@ -310,8 +311,22 @@ func updateStructFromForm(v reflect.Value, formValues map[string][]string, prefi
if configJSON, exists := formValues[fullName]; exists && len(configJSON) > 0 {
var configs map[string]conf.SpeciesConfig
if err := json.Unmarshal([]byte(configJSON[0]), &configs); err != nil {
// Add more detailed error logging
log.Printf("Debug: Failed to unmarshal species config JSON: %s", configJSON[0])
return fmt.Errorf("error unmarshaling species configs for %s: %w", fullName, err)
}

// Clean up the Actions data before setting
for species, config := range configs {
for i := range config.Actions {
// Ensure Parameters is properly initialized as a string slice
if config.Actions[i].Parameters == nil {
config.Actions[i].Parameters = []string{}
}
}
configs[species] = config
}

field.Set(reflect.ValueOf(configs))
}
} else {
Expand Down

0 comments on commit ea40e1c

Please sign in to comment.