Merge pull request #17135 from overleaf/mj-ranges-tracker-error-logs

[ranges-tracker] Move data out of error message

GitOrigin-RevId: 9745661cf75eaed28a133e1ad5eba0bf77d6ecc3
This commit is contained in:
Mathias Jakobsen 2024-03-04 10:35:09 +00:00 committed by Copybot
parent 857a45edeb
commit a4b7c5f468
2 changed files with 4 additions and 18 deletions

View file

@ -195,22 +195,14 @@ class RangesTracker {
if (change.op.i != null) { if (change.op.i != null) {
content = text.slice(change.op.p, change.op.p + change.op.i.length) content = text.slice(change.op.p, change.op.p + change.op.i.length)
if (content !== change.op.i) { if (content !== change.op.i) {
throw new Error( throw new Error('insertion does not match text in document')
`Change (${JSON.stringify(
change
)}) doesn't match text (${JSON.stringify(content)})`
)
} }
} }
} }
for (const comment of this.comments) { for (const comment of this.comments) {
content = text.slice(comment.op.p, comment.op.p + comment.op.c.length) content = text.slice(comment.op.p, comment.op.p + comment.op.c.length)
if (content !== comment.op.c) { if (content !== comment.op.c) {
throw new Error( throw new Error('comment does not match text in document')
`Comment (${JSON.stringify(
comment
)}) doesn't match text (${JSON.stringify(content)})`
)
} }
} }
} }
@ -709,11 +701,7 @@ class RangesTracker {
modification.p + modification.d.length modification.p + modification.d.length
) !== modification.d ) !== modification.d
) { ) {
throw new Error( throw new Error('deletion does not match text in document')
`deleted content does not match. content: ${JSON.stringify(
content
)}; modification: ${JSON.stringify(modification)}`
)
} }
content = content =
content.slice(0, modification.p) + content.slice(0, modification.p) +

View file

@ -179,9 +179,7 @@ describe('RangesManager', function () {
this.updates, this.updates,
this.newDocLines this.newDocLines
) )
}).to.throw( }).to.throw('insertion does not match text in document')
'Change ({"id":"1","op":{"i":"five","p":15},"metadata":{"user_id":"user-id-123"}}) doesn\'t match text ("our ")'
)
}) })
}) })