Improved logs for failed parses

This commit is contained in:
Simon Martens
2025-10-02 00:25:12 +02:00
parent ddd8171c08
commit 6dc9c997ad
2 changed files with 16 additions and 1 deletions

View File

@@ -618,7 +618,9 @@ func (k *KGPZ) Pull() {
if changed {
logging.ObjDebug(&k.Repo, "Remote changed. Reparsing")
k.Serialize()
if err := k.Serialize(); err != nil {
logging.Error(err, "Error parsing XML after git pull. Using mixed old/new data.")
}
k.EnrichAndRebuildIndex()
// Rescan pictures after pull

View File

@@ -1,7 +1,9 @@
package xmlprovider
import (
"fmt"
"slices"
"strings"
"sync"
"time"
@@ -96,12 +98,18 @@ func (p *XMLProvider[T]) Serialize(dataholder XMLRootElement[T], path string, la
func (p *XMLProvider[T]) Cleanup(latest ParseMeta) {
todelete := make([]string, 0)
toappend := make([]*T, 0)
staleDataBySource := make(map[string][]string)
p.Infos.Range(func(key, value interface{}) bool {
info := value.(ItemInfo)
if !info.Parse.Equals(latest) {
if !latest.Failed(info.Source) {
todelete = append(todelete, key.(string))
} else {
// Keep old data because the file failed to parse
keyStr := key.(string)
staleDataBySource[info.Source] = append(staleDataBySource[info.Source], keyStr)
item, ok := p.Items.Load(key)
if ok {
i := item.(*T)
@@ -114,6 +122,11 @@ func (p *XMLProvider[T]) Cleanup(latest ParseMeta) {
return true
})
// Log stale data that is being kept
for source, ids := range staleDataBySource {
logging.Error(nil, "Keeping stale data from failed parse: "+source+" ("+fmt.Sprint(len(ids))+" items: "+strings.Join(ids, ", ")+")")
}
for _, key := range todelete {
p.Infos.Delete(key)
p.Items.Delete(key)