Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use "undefined" as a Firestore value #4

Closed
spadgeaki opened this issue May 6, 2020 · 4 comments · Fixed by boardgameio/boardgame.io#675
Closed

Cannot use "undefined" as a Firestore value #4

spadgeaki opened this issue May 6, 2020 · 4 comments · Fixed by boardgameio/boardgame.io#675

Comments

@spadgeaki
Copy link

Hello, I was trying to setup Firestore as database with my bgio project.

I got this error:

Error: Value for argument "data" is not a valid Firestore document. Cannot use "undefined" as a Firestore value (found in field "unlisted").

It happened when calling setMetadata, arguments look like this:

setMetadata gameID: n_lATufQM metadata: { gameName: 'myGame',
  unlisted: undefined,
  players:
   { '0': { id: 0 },
     '1': { id: 1 },
     '2': { id: 2 },
     '3': { id: 3 },
     '4': { id: 4 },
     '5': { id: 5 },
     '6': { id: 6 },
     '7': { id: 7 },
     '8': { id: 8 },
     '9': { id: 9 },
     '10': { id: 10 } },
  setupData: undefined }

There are actually 2 undefined values in metadata - unlisted and setupData. I don't know if I am doing something wrong in server setup of boardgame.io or if its normal to have these as undefined.

I did simple check for undefined values and deleted them.

Object.keys(metadata).map((key) => {
    if (typeof metadata[key] === "undefined") {
        delete metadata[key]
    }
})

Then everything seems working fine.

Should I make PR with fix like this?

@delucis
Copy link
Owner

delucis commented May 6, 2020

Hi @spadgeaki — thanks for the report. The unlisted field in metadata in a new feature in boardgame.io and I think the bug comes from there: it should probably either be true or false not undefined.

This connector could in theory double check the values for undefined, but that’s probably not the most performant solution if we can avoid it. Let me see if I can get a fix in boardgame.io itself.

@spadgeaki
Copy link
Author

Thanks for a fast reply. There is also second undefined value of setupData. Do you know where does that come from?

@delucis
Copy link
Owner

delucis commented May 6, 2020

Ah, I think the same place — the /games/:name/create endpoint takes optional setupData and unlisted fields in the JSON body, and if these aren’t included, these will both be undefined.

You should be able to use a body like { "unlisted": false, "setupData": null } in your game creation requests to fix these right away if you’re rolling your own API requests.

@spadgeaki
Copy link
Author

Thank you very much. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants