verdigado / rocketchat2matrix

Script to migrate Rocket.Chat databases to Matrix Synapse. Mirror of https://git.verdigado.com/NB-Public/rocketchat2matrix
GNU Affero General Public License v3.0
14 stars 6 forks source link

Error handling RcMessage without the `msg` field defined #19

Open drygdryg opened 4 months ago

drygdryg commented 4 months ago

An error occurs when handling messages:

info: Parsing message with ID: ChT2hXQSAC4RfFimX
error: Encountered an error while booting up: TypeError: Cannot read properties of undefined (reading 'includes') Cannot read properties of undefined (reading 'includes') {"stack":"TypeError: Cannot read properties of undefined (reading 'includes')\n    at mapTextMessage (/home/golovanenko.v/git/rocketchat2matrix/dist/handlers/messages.js:56:13)"}

This error occurs here: https://github.com/verdigado/rocketchat2matrix/blob/13695e0f6f0d6198a2f75e17408ae9215d342147/src/handlers/messages.ts#L103 The problematic message without the msg field:

{
    "_id": "ChT2hXQSAC4RfFimX",
    "_updatedAt": {
        "$date": "2019-09-23T10:39:10.447Z"
    },
    "attachments": [
        {
            "text": "Well, if they are, then you can",
            "author_name": "nucleo",
            "author_icon": "/avatar/nucleo",
            "message_link": "/direct?msg=vWwxtmhkhwZOB8Br4",
            "ts": {
                "$date": "2019-09-23T10:36:32.031Z"
            }
        }
    ],
    "rid": "Zn5ywPXhFkgng6vDq",
    "ts": {
        "$date": "2019-09-23T10:39:10.447Z"
    },
    "u": {
        "_id": "ytJfmk4JD5KDay3Ys",
        "username": "alechka",
        "name": "Alex P."
    }
}

I found 2 similar messages in my Rocket.Chat MongoDB using the query: db.rocketchat_message.find({msg: {$exists: false}})

HerHde commented 4 months ago

Thanks for reporting. After a very quick look I'd assume this is indeed some sort of attachment, although I'd expect something like a file link with it (everything without further investigation).

13 should deal with this, but I didn't had the time to look into it, yet, as I'm finishing tests and parallelisation.