boardgameio / boardgame.io

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

Error when retrieving non-existent game with Firebase RTDB #355

Closed jorbascrumps closed 5 years ago

jorbascrumps commented 5 years ago

I'm attempting to add Firebase storage to my game. I have correctly configured my connection and have been able to store data with Firestore previously. However, I switched to RTDB as that is my preference and received the following error with an empty database:

(node:3700) TypeError: Cannot read property 'G' of null
    at Master.onSync (/Users/chriswright/Code/ascension/server/node_modules/boardgame.io/dist/server.js:3348:39)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

From what I can tell, this error occurs because Firebase#get is returning a null document if it has yet to be created and Master#onSync is expecting undefined when checking if a game has been initialized.

I have not yet fully explored the repercussions of adjusting the Firebase#get return value or updating the condition in Master#onSync (possible inconsistencies with other storage APIs?).

nicolodavis commented 5 years ago

Just noting the other related Firebase issue reported recently: #329.

I'm hoping someone more familiar with Firebase can take a look at this.

jorbascrumps commented 5 years ago

From what I can tell, this is only an issue because Firebase returns null for empty values. I've been poking around and, unless I'm mistaken, the storage APIs are only called in Master. If this is correct, then we could simply coerce the return value of Firebase#get to be undefined instead of null.

What are your thoughts on such a change, @nicolodavis?

nicolodavis commented 5 years ago

Sounds good to me. You can actually verify this without any changes to boardgame.io by copying the firebase adapter implementation and passing it as a custom db adapter to Server in your code.

Feel free to send me a PR if your proposed fix works.