{"record":{"id":"73f319c8a318c4dc","repo":"RocketChat/Rocket.Chat","slug":"error-no-messages","errorCode":"error-no-messages","errorMessage":"No messages found","messagePattern":"No messages found","errorType":"exception","errorClass":"Meteor.Error","httpStatus":400,"severity":"warning","filePath":"apps/meteor/server/api/v1/im.ts","lineNumber":821,"sourceCode":"\t\tif (!room || room?.t !== 'd') {\n\t\t\tthrow new Meteor.Error('error-room-not-found', `No direct message room found by the id of: ${roomId}`);\n\t\t}\n\n\t\tconst { offset, count } = await getPaginationItems(this.queryParams);\n\t\tconst { sort, fields, query } = await this.parseJsonQuery();\n\t\tconst ourQuery = Object.assign({}, query, { rid: room._id });\n\n\t\tconst { cursor, totalCount } = Messages.findPaginated<IMessage>(ourQuery, {\n\t\t\tsort: sort || { ts: -1 },\n\t\t\tskip: offset,\n\t\t\tlimit: count,\n\t\t\tprojection: fields,\n\t\t});\n\n\t\tconst [msgs, total] = await Promise.all([cursor.toArray(), totalCount]);\n\n\t\tif (!msgs) {\n\t\t\tthrow new Meteor.Error('error-no-messages', 'No messages found');\n\t\t}\n\n\t\treturn API.v1.success({\n\t\t\tmessages: await normalizeMessagesForUser(msgs, this.userId),\n\t\t\toffset,\n\t\t\tcount: msgs.length,\n\t\t\ttotal,\n\t\t});\n\t};\n\nconst dmListEndpointsProps = {\n\tauthRequired: true as const,\n\tresponse: {\n\t\t200: paginatedImsResponseSchema,\n\t\t400: validateBadRequestErrorResponse,\n\t\t401: validateUnauthorizedErrorResponse,\n\t},\n};","sourceCodeStart":803,"sourceCodeEnd":839,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/im.ts#L803-L839","documentation":"After Messages.findPaginated, dmMessagesOthersAction awaits [msgs, total] and throws error-no-messages when !msgs. In practice this branch is effectively dead code: cursor.toArray() always resolves to an array (possibly empty), which is truthy, so the guard never trips. An empty result instead returns count:0 with an empty messages array. Treat any observed occurrence as a driver/cursor anomaly rather than an empty-room condition.","triggerScenarios":"Effectively unreachable under normal MongoDB driver behavior — would require cursor.toArray() to resolve to null/undefined. Empty message sets do NOT trigger this; they return success with count 0.","commonSituations":"Should not occur in practice. If reported, suspect a mocked/custom cursor, an exotic driver version, or a misattributed error code.","solutions":["Do not try to 'fix' empty rooms here — an empty result returns 200 with count 0.","If genuinely hit, inspect the Messages cursor/driver in use.","Report as a likely dead-code path; the intent was probably `if (!msgs.length)`."],"exampleFix":"// current (effectively unreachable)\nif (!msgs) { throw new Meteor.Error('error-no-messages', 'No messages found'); }\n\n// probable intent\nif (!msgs.length) { return API.v1.success({ messages: [], offset, count: 0, total }); }","handlingStrategy":"try-catch","validationCode":"// No caller-side prevention needed: empty results return 200 with count 0.\n// If you truly see error-no-messages, log the driver/cursor state for investigation.\nconst log = (msg) => console.warn('[im.messages.others]', msg);","typeGuard":null,"tryCatchPattern":"try {\n  const r = await api.get('/api/v1/im.messages.others', { params: { roomId } });\n  // empty is normal: r.data.count === 0\n} catch (e) {\n  if (e.response?.data?.error === 'error-no-messages') {\n    // unexpected — treat as success with empty list and report upstream\n  } else throw e;\n}","preventionTips":["Do not interpret 'no messages' as this error — empty rooms return count 0.","If observed, capture the MongoDB driver version and cursor state.","File an issue: the guard likely meant `!msgs.length`, not `!msgs`."],"tags":["dead-code","direct-message","api","defensive"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}