boardgameio / boardgame.io

State Management and Multiplayer Networking for Turn-Based Games
https://boardgame.io
MIT License
10.03k stars 709 forks source link

Server throwing unhandledRejection #177

Closed Toktik closed 6 years ago

Toktik commented 6 years ago

It happens when doing any move. Using 0.21.5.

unhandledRejection TypeError: Cannot read property 'allowedMoves' of undefined
    at canMakeMove (C:\projects\playbg\node_modules\boardgame.io\dist\core.js:1481:22)
    at Object.canMakeMove (C:\projects\playbg\node_modules\boardgame.io\dist\core.js:971:14)
    at Socket.<anonymous> (C:\projects\playbg\node_modules\boardgame.io\dist\server.js:1241:26)
    at <anonymous>
jstacoder commented 6 years ago

Is there anyway you could provide the object your passing to Game? It would help add context to the error.

Stefan-Hanke commented 6 years ago

Please add repro steps, or provide your code.

The multiplayer examples utilizing the server seem to work. I've manually deleted _nodemodules and dist, merged latest, ran npm i and then npm run examples. Maybe I've missed something, the command is showing that the dev server is using 0.21.5.

The code in question fetches the phase from the phase map, and calls allowedMoves on it. allowedMoves is guaranteed to be a function as per that code. Looks like the problem is somewhere in either the phase config or the phase code.

Toktik commented 6 years ago

Here is the code: https://pastebin.com/a8U4fTBs

I observe that the canMakeMove() is called twice. First time phaseMap contains default phase only (not sure what it is), and it throws an error, because there is no ctx.phase in phaseMap. Second time it contains all my phases.

Stefan-Hanke commented 6 years ago

Weird. The default phase is only used if no phases is passed to the flow. Since the code passes one, you should not see it at all.

Thanks for the code, I'm trying to somehow repro your scenario with it, atm to no avail. Could you share a complete example that demonstrates the issue?

nicolodavis commented 6 years ago

Closing this for now. @Toktik Feel free to ask at https://gitter.im/boardgame-io/General if you continue to have any problems.