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

"undefined" as a Firestore value found in field "action.payload.playerID" #5

Closed
fzf opened this issue Jun 4, 2020 · 5 comments
Closed

Comments

@fzf
Copy link

fzf commented Jun 4, 2020

I basically running the tutorial and am having a little issue with sending payloads to firebase, it says I could turn on ignoreUndefinedProperties is there a way to set that setting?

I tried setting it with:

const database = new Firestore({
  config: {
    credential: admin.credential.applicationDefault(),
    databaseURL: 'https://xxx.firebaseio.com',
  },
});
database.db.settings({...database.db.settings, ignoreUndefinedProperties: true })

But that results in a (node:82194) UnhandledPromiseRejectionWarning: Error: 5 NOT_FOUND: No document to update: projects/boardgameio/databases/(default)/documents/bgio_log/default error.

Let me know if you need anymore information, thanks for the awesome package!

(node:42090) UnhandledPromiseRejectionWarning: Error: Element at index 1 is not a valid array element. Cannot use "undefined" as a Firestore value (found in field "action.payload.playerID"). If you want to ignore undefined values, enable `ignoreUndefinedProperties`.
    at validateUserInput (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/serializer.js:269:19)
    at validateUserInput (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/serializer.js:260:13)
    at validateUserInput (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/serializer.js:260:13)
    at Object.validateUserInput (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/serializer.js:260:13)
    at validateArrayElement (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/field-value.js:428:18)
    at ArrayUnionTransform.validate (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/field-value.js:353:13)
    at /Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/document.js:783:56
    at Map.forEach (<anonymous>)
    at DocumentTransform.validate (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/document.js:783:25)
    at WriteBatch.update (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/write-batch.js:379:19)
    at process.emitWarning (internal/process/warning.js:132:11)
    at process.<anonymous> (/Users/fzf/Projects/game/node_modules/esm/esm.js:1:289642)
    at process.<anonymous> (/Users/fzf/Projects/game/node_modules/esm/esm.js:1:289518)
    at process.<anonymous> (/Users/fzf/Projects/game/node_modules/esm/esm.js:1:284879)
    at Object.apply (/Users/fzf/Projects/game/node_modules/esm/esm.js:1:199341)
    at emitUnhandledRejectionWarning (internal/process/promises.js:149:15)
    at processPromiseRejections (internal/process/promises.js:211:11)
    at processTicksAndRejections (internal/process/task_queues.js:98:32)
(node:42090) Error: Element at index 1 is not a valid array element. Cannot use "undefined" as a Firestore value (found in field "action.payload.playerID"). If you want to ignore undefined values, enable `ignoreUndefinedProperties`.
    at validateUserInput (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/serializer.js:269:19)
    at validateUserInput (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/serializer.js:260:13)
    at validateUserInput (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/serializer.js:260:13)
    at Object.validateUserInput (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/serializer.js:260:13)
    at validateArrayElement (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/field-value.js:428:18)
    at ArrayUnionTransform.validate (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/field-value.js:353:13)
    at /Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/document.js:783:56
    at Map.forEach (<anonymous>)
    at DocumentTransform.validate (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/document.js:783:25)
    at WriteBatch.update (/Users/fzf/Projects/game/node_modules/@google-cloud/firestore/build/src/write-batch.js:379:19)
(node:42090) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    at process.emitWarning (internal/process/warning.js:132:11)
    at process.<anonymous> (/Users/fzf/Projects/game/node_modules/esm/esm.js:1:289642)
    at process.<anonymous> (/Users/fzf/Projects/game/node_modules/esm/esm.js:1:289518)
    at process.<anonymous> (/Users/fzf/Projects/game/node_modules/esm/esm.js:1:284879)
    at Object.apply (/Users/fzf/Projects/game/node_modules/esm/esm.js:1:199341)
    at emitDeprecationWarning (internal/process/promises.js:161:11)
    at processPromiseRejections (internal/process/promises.js:213:13)
    at processTicksAndRejections (internal/process/task_queues.js:98:32)
^C
@delucis
Copy link
Owner

delucis commented Jun 4, 2020

Hi — thanks for the report. I wasn’t aware of the new ignoreUndefinedProperties. That’s pretty useful as there are a few corners where boardgame.io throws up undefined and I’d been resisting adding something like JSON.parse(JSON.stringify(data)) for every operation to strip them out.

I think there are actually two errors here:

  1. If boardgame.io returns undefined we run into the obvious error. Once you set the ignoreUndefinedProperties option, you actually fixed that.

  2. The “No document to update” error is because the game log document is missing when storing game state. The log document is initialised when a game is created but subsequently, we only append to it, so there’s an error if for some reason it wasn’t created.

Couple of questions:

  • Are you using the boardgame.io Lobby REST API to create games?

  • Keeping the ignoreUndefinedProperties option, and creating a new game, do you still see errors?

I think it would be nice if we can set the ignoreUndefinedProperties internally — although the fact that settings() errors if called more than once is kind of annoying — and maybe we should use a less brittle approach to the log management, not relying on update.

@delucis
Copy link
Owner

delucis commented Jun 4, 2020

Update: I released 0.1.1, which uses the ignoreUndefinedProperties by default. I’d still be curious if you’re using the Lobby API & if you see errors for new games before deciding what to do about managing the game logs.

@fzf
Copy link
Author

fzf commented Jun 4, 2020

This is awesome, thanks for updating that, I am not currently using the Lobby API I will update my project tonight to use that for game provisioning and give you an answer on the error with a new game.

@delucis
Copy link
Owner

delucis commented Jun 4, 2020

@fzf Ah, that’s already good to know. I had a suspicion you might not be using the Lobby API. I think boardgame.io doesn’t call a database’s createGame method if the game isn’t created via the Lobby API, so that’s why the way I’ve designed the log initialisation here doesn’t work.

@fzf
Copy link
Author

fzf commented Jun 5, 2020

Just as you said, it worked correctly when the game is created through the Lobby component. Watching #722 but this is resolved!

@fzf fzf closed this as completed Jun 5, 2020
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

No branches or pull requests

2 participants