NanderTGA / msgroom-orm

A MsgRoom client.
https://nandertga.github.io/msgroom-orm/
MIT License
4 stars 0 forks source link

Running a subcommand without the actual subcommand crashes #55

Closed mybearworld closed 1 year ago

mybearworld commented 1 year ago

If you have subcommands like !a b, !a c, !a d, just trying to call !a crashes msgroom-nightly. Here's the error from toB:

<toBPath>\node_modules\msgroom-nightly\dist\index.js:281
                    if (key.toLowerCase() == command.toLowerCase()) {
                                                     ^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at Client.getCommand (<toBPath>\node_modules\msgroom-nightly\dist\index.js:281:54)
    at Client.processCommands (<toBPath>\node_modules\msgroom-nightly\dist\index.js:317:42)
    at Socket.<anonymous> (<toBPath>\node_modules\msgroom-nightly\dist\index.js:136:27)
    at Emitter.emit (<toBPath>\node_modules\@socket.io\component-emitter\index.js:143:20)
    at Socket.emitEvent (<toBPath>\node_modules\socket.io-client\build\cjs\socket.js:519:20)
    at Socket.onevent (<toBPath>\node_modules\socket.io-client\build\cjs\socket.js:506:18)
    at Socket.onpacket (<toBPath>\node_modules\socket.io-client\build\cjs\socket.js:474:22)
    at Emitter.emit (<toBPath>\node_modules\@socket.io\component-emitter\index.js:143:20)
    at <toBPath>\node_modules\socket.io-client\build\cjs\manager.js:237:18
    at process.processTicksAndRejections (node:internal/process/task_queues:81:21)

Node.js v18.16.0
NanderTGA commented 1 year ago

Does !a undefined exist?

mybearworld commented 1 year ago

What do you mean? I have not specified an undefined property on the object.

NanderTGA commented 1 year ago

On a, you have properties b, c, etc. If you don't have a property called undefined, bad stuff could happen as I just remembered I didn't test that.

NanderTGA commented 1 year ago

When you execute !a, it will actually call !a undefined

NanderTGA commented 1 year ago

I tested your code and you need to add the undefined property to make it stop crashing, like this: afbeelding

NanderTGA commented 1 year ago

Every commandMap is expected to have this property (except client.commands). I need to add some checks for this maybe.

mybearworld commented 1 year ago

I tested your code and you need to add the undefined property to make it stop crashing, like this: afbeelding

Okay, thank you, I wasn't aware of this - in earlier versions, it would just not do anything.

NanderTGA commented 1 year ago

The undefined commands are a giant mess, my apologies for that.

43 will fix this, and I'll add a note somewhere to check if the handler property actually exists, incase someone would forget somehow. I'll use this issue as that note.

NanderTGA commented 1 year ago

This confusion will not happen anymore with the new metadata for (sub)commands system, see #43.