Skip to content

Commit

Permalink
Ignore invalid numbers when saving widget settings
Browse files Browse the repository at this point in the history
When setting to "" or "0" it would error out. It's not really worth it
returning proper errors, as it returns HTML and we'd have to do some
special-fu for that. Just ignoring is okay, and better than "Could not
load /user/dashboard/0".
  • Loading branch information
arp242 committed Aug 19, 2024
1 parent 0f60e64 commit 99c1dcf
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,10 @@ func (w Widget) SetSetting(ctx context.Context, widget, setting, value string) e
}
switch def.Type {
case "number":
n, err := strconv.Atoi(value)
if err != nil {
return fmt.Errorf("Widget.SetSetting: setting %q for widget %q: %w", setting, widget, err)
n, _ := strconv.Atoi(value)
if n > 0 {
s[setting] = float64(n)
}
s[setting] = float64(n)
case "checkbox":
s[setting] = value == "on"
case "text", "select":
Expand Down

0 comments on commit 99c1dcf

Please sign in to comment.