From 9fef1552fcc86a33cd5f92bc05b9fef2e6771fd8 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Wed, 10 Jul 2019 10:57:49 +0200 Subject: [PATCH] lib/db, lib/model: Remove folder info from panics (ref #5839) (#5840) --- lib/db/instance.go | 3 ++- lib/model/model.go | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/db/instance.go b/lib/db/instance.go index b07c8aef0..d88dd7e33 100644 --- a/lib/db/instance.go +++ b/lib/db/instance.go @@ -172,7 +172,8 @@ func (db *instance) withHaveSequence(folder []byte, startSeq int64, fn Iterator) if shouldDebug() { if seq := db.keyer.SequenceFromSequenceKey(dbi.Key()); f.Sequence != seq { - panic(fmt.Sprintf("sequence index corruption (folder %v, file %v): sequence %d != expected %d", string(folder), f.Name, f.Sequence, seq)) + l.Warnf("Sequence index corruption (folder %v, file %v): sequence %d != expected %d", string(folder), f.Name, f.Sequence, seq) + panic("sequence index corruption") } } if !fn(f) { diff --git a/lib/model/model.go b/lib/model/model.go index e8b149db0..4408daeeb 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -257,9 +257,11 @@ func (m *model) StartFolder(folder string) { // Need to hold lock on m.fmut when calling this. func (m *model) startFolderLocked(cfg config.FolderConfiguration) { if err := m.checkFolderRunningLocked(cfg.ID); err == errFolderMissing { - panic("cannot start nonexistent folder " + cfg.Description()) + l.Warnln("Cannot start nonexistent folder", cfg.Description()) + panic("cannot start nonexistent folder") } else if err == nil { - panic("cannot start already running folder " + cfg.Description()) + l.Warnln("Cannot start already running folder", cfg.Description()) + panic("cannot start already running folder") } folderFactory, ok := folderFactories[cfg.Type] @@ -435,7 +437,8 @@ func (m *model) RestartFolder(from, to config.FolderConfiguration) { panic("bug: cannot restart empty folder ID") } if to.ID != from.ID { - panic(fmt.Sprintf("bug: folder restart cannot change ID %q -> %q", from.ID, to.ID)) + l.Warnf("bug: folder restart cannot change ID %q -> %q", from.ID, to.ID) + panic("bug: folder restart cannot change ID") } // This mutex protects the entirety of the restart operation, preventing @@ -995,7 +998,8 @@ func (m *model) handleIndex(deviceID protocol.DeviceID, folder string, fs []prot m.fmut.RUnlock() if !existing { - panic(fmt.Sprintf("%v for nonexistent folder %q", op, folder)) + l.Warnf("%v for nonexistent folder %q", op, folder) + panic("handling index for nonexistent folder") } if running { @@ -1003,7 +1007,8 @@ func (m *model) handleIndex(deviceID protocol.DeviceID, folder string, fs []prot } else if update { // Runner may legitimately not be set if this is the "cleanup" Index // message at startup. - panic(fmt.Sprintf("%v for not running folder %q", op, folder)) + l.Warnf("%v for not running folder %q", op, folder) + panic("handling index for not running folder") } m.pmut.RLock()