Skip to content

Commit 5c75906

Browse files
committed
Assert for length check in ChangeVersionString
1 parent a3b1bd8 commit 5c75906

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

db/changes.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ func ParseChangesVersionType(s string) (ChangesVersionType, error) {
6565
}
6666

6767
// ChangeVersionString returns the first version string we found in the ChangeEntry.
68-
func (ce *ChangeEntry) ChangeVersionString() string {
68+
func (ce *ChangeEntry) ChangeVersionString(ctx context.Context) string {
69+
if len(ce.Changes) == 0 {
70+
base.AssertfCtx(ctx, "ChangesEntry has no changes: %s", ce.String())
71+
return ""
72+
}
6973
// pick just the first entry in changes
7074
for _, changeVersionString := range ce.Changes[0] {
7175
// whichever version is present we'll return it - only expected to have one version type populated - since the feed is initialized with a preferred version type.
@@ -163,7 +167,7 @@ func (db *DatabaseCollectionWithUser) addDocToChangeEntry(ctx context.Context, e
163167

164168
} else if options.IncludeDocs {
165169
// Retrieve document via rev cache
166-
revID := entry.ChangeVersionString()
170+
revID := entry.ChangeVersionString(ctx)
167171
err := db.AddDocToChangeEntryUsingRevCache(ctx, entry, revID)
168172
if err != nil {
169173
base.WarnfCtx(ctx, "Changes feed: error getting revision body for %q (%s): %v", base.UD(entry.ID), revID, err)
@@ -187,7 +191,7 @@ func (db *DatabaseCollectionWithUser) AddDocInstanceToChangeEntry(ctx context.Co
187191

188192
includeConflicts := options.Conflicts && entry.branched
189193

190-
revID := entry.ChangeVersionString()
194+
revID := entry.ChangeVersionString(ctx)
191195
if includeConflicts {
192196
// should've been validated in the handler layer but be defensive
193197
if options.VersionType == ChangesVersionTypeCV {
@@ -592,7 +596,7 @@ func (ce *ChangeEntry) AuditReadEvent(ctx context.Context) {
592596
}
593597
base.Audit(ctx, base.AuditIDDocumentRead, base.AuditFields{
594598
base.AuditFieldDocID: ce.ID,
595-
base.AuditFieldDocVersion: ce.ChangeVersionString(),
599+
base.AuditFieldDocVersion: ce.ChangeVersionString(ctx),
596600
})
597601
}
598602

0 commit comments

Comments
 (0)