fix(sync): prevent nil pointer dereference when existing progress is missing

In applyProgressResolution and applyResolution, currentPage and totalPages
were unconditionally read from existingProgress even when the preceding
query returned err (no rows). This caused a nil pointer dereference when
no existing reading progress existed for a media item. Now declare the
variables as zero-value pgtype.Int4 and only populate them from
existingProgress when err is nil.
This commit is contained in:
2026-04-20 20:45:41 -04:00
parent 3e73a582ba
commit 18811cea1b
+12 -4
View File
@@ -316,8 +316,12 @@ func (h *ConflictHandler) applyProgressResolution(mediaItemID pgtype.UUID, userI
characterOffset = pgtype.Int8{Int64: int64(c), Valid: true}
}
currentPage := existingProgress.CurrentPage
totalPages := existingProgress.TotalPages
var currentPage pgtype.Int4
var totalPages pgtype.Int4
if err == nil {
currentPage = existingProgress.CurrentPage
totalPages = existingProgress.TotalPages
}
if p, ok := data["page"].(float64); ok {
currentPage = pgtype.Int4{Int32: int32(p), Valid: true}
@@ -661,8 +665,12 @@ func (h *ConflictHandler) applyResolution(mediaItemID pgtype.UUID, userID pgtype
characterOffset = pgtype.Int8{Int64: int64(c), Valid: true}
}
currentPage := existingProgress.CurrentPage
totalPages := existingProgress.TotalPages
var currentPage pgtype.Int4
var totalPages pgtype.Int4
if err == nil {
currentPage = existingProgress.CurrentPage
totalPages = existingProgress.TotalPages
}
if p, ok := data["page"].(float64); ok {
currentPage = pgtype.Int4{Int32: int32(p), Valid: true}