matrix-js-sdk icon indicating copy to clipboard operation
matrix-js-sdk copied to clipboard

"Fatal undefined"

Open alexgleason opened this issue 6 years ago • 7 comments

I'm trying to make a simple bot that responds to new members. I'm getting "Fatal undefined" which isn't helpful at solving the problem. Is there a way to better debug?

Thank you!

alexgleason avatar Feb 14 '19 17:02 alexgleason

I'm having the same issue and no response on this thread makes me worried :crying_cat_face:

marcinciarka avatar Feb 20 '19 10:02 marcinciarka

Can you describe how you are using the SDK? I agree it sounds like an unhelpful error. Hopefully we can figure it out!

jryans avatar Feb 20 '19 11:02 jryans

(sry for reposting)

For me it's pretty basic stuff:

const sdk = require('matrix-js-sdk');
const myUserId = 'x';
const myAccessToken = 'xxx';
const matrixClient = sdk.createClient({
    baseUrl: 'xxx',
    accessToken: myAccessToken,
    userId: myUserId
});

matrixClient.on('sync', (syncState, a, event) => {
    console.log('syncState', syncState);
    console.log('event', event);
    console.log('a', a);
    
    if (syncState === 'PREPARED') {
        matrixClient.on("Room.timeline", function(event, room) {
            ('do stuff')
        });
    }
})

matrixClient.startClient();

node is outputting:

Got push rules
Sending first sync request...
syncState PREPARED
event { oldSyncToken: null,
  nextSyncToken: 'xxx',
  catchingUp: false }
a null
syncState SYNCING
event { oldSyncToken: null,
  nextSyncToken: 'xxx',
  catchingUp: false }
a PREPARED
Fatal undefined

marcinciarka avatar Feb 20 '19 11:02 marcinciarka

            ('do stuff')

looks very invalid

What do you actually have here?

t3chguy avatar Feb 20 '19 12:02 t3chguy

('do stuff')

It's valid JS (I just cut out the irrelevant part...), but it doesn't matter, because nothing inside matrixClient.on('sync', () => {}) is being executed. Let's change this to:

    if (syncState === 'PREPARED') {
        matrixClient.on("Room.timeline", function(event, room) {
            console.log(event, room)
        });
    }

It just goes PREPARED => SYNCING and then Fatal undefined.

marcinciarka avatar Feb 20 '19 12:02 marcinciarka

After a little digging i've found out that the piece of code from the docs is causing the trouble:

   matrixClient.on("RoomMember.membership", function(event, member) {
       if (member.membership === "invite" && member.userId === myUserId) {
           matrixClient.joinRoom(member.roomId).done(function() {
               console.log("Auto-joined %s", member.roomId);
           });
       }
   });

But I'm not able to resolve this issue, so for the time being I will just comment this out.

--- EDIT

I've managed to gain more information - I've logged into riot web using the bot account and left the channel which was causing trouble. The bot was invited and then kicked from it.

marcinciarka avatar Feb 20 '19 13:02 marcinciarka

I was also getting this error using a bot with only the auto-invite script just (like the comment above). Aside from matrixClient.start() or whatever, that was the only code.

It would crash right after starting, with the cryptic "Fatal undefined." Interesting that a room state could cause this.

EDIT: I had also kicked the bot from the room then re-invited it.

alexgleason avatar Feb 26 '19 21:02 alexgleason