From 3603bc5e25fc547e13ad0d2814685b562066f7e9 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Tue, 27 Jan 2026 15:48:17 +0100 Subject: [PATCH] [real-time] handle getDocument result in case of an error GitOrigin-RevId: 592be03d7b93a3d1f86015e58d2de5d2f12d89f6 --- .../real-time/app/js/WebsocketController.js | 3 ++- .../test/unit/js/WebsocketController.test.js | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/services/real-time/app/js/WebsocketController.js b/services/real-time/app/js/WebsocketController.js index c0b5faf669..90128be1e5 100644 --- a/services/real-time/app/js/WebsocketController.js +++ b/services/real-time/app/js/WebsocketController.js @@ -287,13 +287,14 @@ export default WebsocketController = { projectId, docId, fromVersion, - function (error, { lines, version, ranges, ops, ttlInS, type }) { + function (error, result) { if (error) { if (error instanceof ClientRequestedMissingOpsError) { emitJoinDocCatchUpMetrics('missing', error.info) } return callback(error) } + const { lines, version, ranges, ops, ttlInS, type } = result emitJoinDocCatchUpMetrics('success', { version, ttlInS }) if (client.disconnected) { metrics.inc('editor.join-doc.disconnected', 1, { diff --git a/services/real-time/test/unit/js/WebsocketController.test.js b/services/real-time/test/unit/js/WebsocketController.test.js index fa57d0fccd..d0e102ed2c 100644 --- a/services/real-time/test/unit/js/WebsocketController.test.js +++ b/services/real-time/test/unit/js/WebsocketController.test.js @@ -728,6 +728,28 @@ describe('WebsocketController', function () { }) }) + describe('when the DocumentUpdaterManager returns an error', function () { + beforeEach(function (ctx) { + ctx.err = new Error('document updater error') + ctx.DocumentUpdaterManager.getDocument = sinon + .stub() + .callsArgWith(3, ctx.err) + ctx.WebsocketController.joinDoc( + ctx.client, + ctx.doc_id, + -1, + ctx.options, + ctx.callback + ) + }) + + it('should call the callback with the error', function (ctx) { + ctx.callback + .calledWith(sinon.match({ message: 'document updater error' })) + .should.equal(true) + }) + }) + describe('with a restricted client', function () { beforeEach(function (ctx) { ctx.ranges.comments = [{ op: { a: 1 } }, { op: { a: 2 } }]