detached 7d7aff9

fix: verify all value types and handle reload error after restore

Address CodeRabbit findings:
- verifyCriticalFields now uses reflect.DeepEqual to catch corruption
  of booleans, integers, and other non-string fields
- ReadInConfig error after backup restore is now logged instead of silenced
commit
7d7aff9589ffe1e748e5e5f495e3acaf8ea74ccb
author
brice · · 2026-03-14 05:02 UTC
parent
460e4c5
signature
unsigned
1 file · +7 -7
M internal/usecase/config/service.go +7 -7
@@ -5,6 +5,7 @@ import (
55 "context"
66 "fmt"
77 "os"
8+ "reflect"
89 "strings"
910 "sync"
1011 "sync/atomic"
@@ -481,8 +482,9 @@ func (s *Service) Save(ctx context.Context) error {
481482 log.Error().Err(err).Msg("config corruption detected after save, restoring backup")
482483 if restoreErr := restoreConfigBackup(configFile); restoreErr != nil {
483484 log.Error().Err(restoreErr).Msg("CRITICAL: failed to restore config backup")
485+ } else if reloadErr := s.viper.ReadInConfig(); reloadErr != nil {
486+ log.Error().Err(reloadErr).Msg("failed to reload config after restore")
484487 }
485- _ = s.viper.ReadInConfig()
486488 return log.WrapErr(err, "config verification failed after save")
487489 }
488490
@@ -504,14 +506,12 @@ func (s *Service) snapshotCriticalFields() configSnapshot {
504506
505507 func (s *Service) verifyCriticalFields(snap configSnapshot) error {
506508 for key, oldVal := range snap.values {
507- oldStr, ok := oldVal.(string)
508- if !ok || oldStr == "" {
509+ if oldVal == nil {
509510 continue
510511 }
511-
512- newVal := s.viper.GetString(key)
513- if newVal != oldStr {
514- return fmt.Errorf("config key %q changed from %q to %q after save", key, oldStr, newVal)
512+ newVal := s.viper.Get(key)
513+ if !reflect.DeepEqual(oldVal, newVal) {
514+ return fmt.Errorf("config key %q changed from %v to %v after save", key, oldVal, newVal)
515515 }
516516 }
517517
@@ -5,6 +5,7 @@ import (
5 "context"5 "context"
6 "fmt"6 "fmt"
7 "os"7 "os"
8+ "reflect"
8 "strings"9 "strings"
9 "sync"10 "sync"
10 "sync/atomic"11 "sync/atomic"
@@ -481,8 +482,9 @@ func (s *Service) Save(ctx context.Context) error {
481 log.Error().Err(err).Msg("config corruption detected after save, restoring backup")482 log.Error().Err(err).Msg("config corruption detected after save, restoring backup")
482 if restoreErr := restoreConfigBackup(configFile); restoreErr != nil {483 if restoreErr := restoreConfigBackup(configFile); restoreErr != nil {
483 log.Error().Err(restoreErr).Msg("CRITICAL: failed to restore config backup")484 log.Error().Err(restoreErr).Msg("CRITICAL: failed to restore config backup")
485+ } else if reloadErr := s.viper.ReadInConfig(); reloadErr != nil {
486+ log.Error().Err(reloadErr).Msg("failed to reload config after restore")
484 }487 }
485- _ = s.viper.ReadInConfig()
486 return log.WrapErr(err, "config verification failed after save")488 return log.WrapErr(err, "config verification failed after save")
487 }489 }
488 490
@@ -504,14 +506,12 @@ func (s *Service) snapshotCriticalFields() configSnapshot {
504 506
505 func (s *Service) verifyCriticalFields(snap configSnapshot) error {507 func (s *Service) verifyCriticalFields(snap configSnapshot) error {
506 for key, oldVal := range snap.values {508 for key, oldVal := range snap.values {
507- oldStr, ok := oldVal.(string)509+ if oldVal == nil {
508- if !ok || oldStr == "" {
509 continue510 continue
510 }511 }
511-512+ newVal := s.viper.Get(key)
512- newVal := s.viper.GetString(key)513+ if !reflect.DeepEqual(oldVal, newVal) {
513- if newVal != oldStr {514+ return fmt.Errorf("config key %q changed from %v to %v after save", key, oldVal, newVal)
514- return fmt.Errorf("config key %q changed from %q to %q after save", key, oldStr, newVal)
515 }515 }
516 }516 }
517 517

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close