empiricaly / empirica

Open source project to tackle the problem of long development cycles required to produce software to conduct multi-participant and real-time human experiments online.
https://empirica.ly/
Apache License 2.0
44 stars 8 forks source link

`player.stage` is sometimes undefined #476

Closed frasalvi closed 4 months ago

frasalvi commented 7 months ago

Is there an existing issue for this?

What happened?

Sometimes, the value of player.stage seems to be undefined.

I have been catching this error through Sentry, when one player transitioned from one stage to the following one (actually, from the last stage to the exit steps). In Stage.jsx:

TypeError: Cannot read properties of undefined (reading 'get')

When trying to call player.stage.get("submit").

Seems related to #455: could it be that the problem has the same origin?

Steps To Reproduce

This only happened once so far to me, and I haven't managed to reproduce it.

Empirica Version

Version: v1.8.12
SHA:     656d19b
Build:   159
Branch:  main
Time:    2023-12-26T07:14:40Z

What OS are you seeing the problem on?

macOS

What browser are you seeing the problem on?

Chrome

Relevant log output

No response

Anything else?

No response

Code of Conduct

npaton commented 7 months ago

This should be fixed in the latest release (1.9.0). I managed to reproduce and have tests covering this now. Let me know if ever you see it happen again.

frasalvi commented 7 months ago

@npaton thanks! Just a quick question on this: I saw that https://github.com/empiricaly/empirica/commit/b32b95ab2bbf4e7298ca8a18ed860a15f7c19045 checks for allReady after the checks for player.get("ended"). If I understand it correctly, this means that those checks do not cover the Exit steps, where indeed I have been getting errors such as usePlayers(), player.game, and even usePlayer() being undefined. Is this by design, i.e. we are not supposed to use those hooks in the Exit steps?

npaton commented 7 months ago

Those are indeed undefined in intro and exit steps by design. A few people have been asking about this, so we might change it. The original idea was that once the player had finished the game they should not be able to see any of its data. If the experimenter wants to use any game data, they should copy it onto the player object on game exit. But we might want to reconsider if everyone wants this data to remain available.

frasalvi commented 7 months ago

Thanks for the clarification.

Unfortunately, this happened again with 1.9.0. I'm copying the full trace below this time:

TypeError: Cannot read properties of undefined (reading 'get')
  at Stage(/assets/index.4765b277.js:41410:21)
  at Xh(/assets/index.4765b277.js:17726:7)
  at dj(/assets/index.4765b277.js:18339:8)
  at Wk(/assets/index.4765b277.js:20859:93)
  at Vk(/assets/index.4765b277.js:20489:11)
  at Uk(/assets/index.4765b277.js:20482:5)
  at Jk(/assets/index.4765b277.js:20465:7)
  at Ok(/assets/index.4765b277.js:20181:7)
  at Hk(/assets/index.4765b277.js:20112:55)
  at J2(/assets/index.4765b277.js:14412:20)
  at MessagePort.R2(/assets/index.4765b277.js:14442:13)
npaton commented 7 months ago

I haven't been able to reproduce this yet. Would you be able to share your code with me? If it's private, maybe you can invite me to the repo? Thanks!

frasalvi commented 7 months ago

Following up on Slack!

emilygoodwin commented 7 months ago

Hi everyone, thank you so much for your hard work on this issue! I'm also experiencing the same error, running 1.9.2.

The line in my code is trying to access batch.games[0].get("treatment"), and getting that "treatment" property was not causing errors in earlier empirica versions (v1.4.6). I am happy to add anyone to the repo if that helps but it is currently set to private.

As far as I can tell, it always happens on the second batch I create: I can do 1 batch with 1 game soup to nuts no problem, but then the second batch I create (without restarting the server) I get the following errors:

Batch 01HKX4MRJC97MYK2REC0JFBHH0 changed status to "running" 20:51:28.707 ERR Error caught in "batch.status" callback: 20:51:29.207 ERR TypeError: Cannot read properties of undefined (reading 'get') 20:51:29.211 ERR at Object.callback (/tmp/121f3729ba799437/src/callbacks.js:12:36) 20:51:29.211 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) Batch 01HKX4BH1Q3BC4WDJ2GZHXWTCS changed status to "ended" 20:51:29.215 ERR Error caught in "batch.status" callback: 20:51:29.578 ERR TypeError: Cannot read properties of undefined (reading 'get') 20:51:29.579 ERR at Object.callback (/tmp/121f3729ba799437/src/callbacks.js:12:36) 20:51:29.580 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) 20:51:29.580 INF server: started 20:51:34.546 ERR Error caught in "player.introDone" callback: 20:51:34.836 ERR ZodError: [ 20:51:34.836 ERR { 20:51:34.836 ERR "code": "invalid_type", 20:51:34.837 ERR "expected": "object", 20:51:34.837 ERR "received": "undefined", 20:51:34.837 ERR "path": [], 20:51:34.837 ERR "message": "Required" 20:51:34.838 ERR } 20:51:34.838 ERR ] 20:51:34.838 ERR ZodError: [ 20:51:34.838 ERR { 20:51:34.838 ERR "code": "invalid_type", 20:51:34.838 ERR "expected": "object", 20:51:34.838 ERR "received": "undefined", 20:51:34.838 ERR "path": [], 20:51:34.838 ERR "message": "Required" 20:51:34.838 ERR } 20:51:34.838 ERR ] 20:51:34.839 ERR at o7 (/tmp/121f3729ba799437/node_modules/zod/lib/index.mjs:449:23) 20:51:34.839 ERR at Va.safeParse (/tmp/121f3729ba799437/node_modules/zod/lib/index.mjs:561:16) 20:51:34.839 ERR at Va.parse (/tmp/121f3729ba799437/node_modules/zod/lib/index.mjs:541:29) 20:51:34.839 ERR at Object.callback (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/classic/classic.ts:460:39) 20:51:34.839 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) 20:51:34.839 ERR at runMicrotasks (<anonymous>) 20:51:34.839 ERR at processTicksAndRejections (node:internal/process/task_queues:96:5) 20:51:34.839 ERR Error caught in "player.introDone" callback: 20:51:35.061 ERR ZodError: [ 20:51:35.063 ERR { 20:51:35.063 ERR "code": "invalid_type", 20:51:35.063 ERR "expected": "object", 20:51:35.063 ERR "received": "undefined", 20:51:35.063 ERR "path": [], 20:51:35.063 ERR "message": "Required" 20:51:35.064 ERR } 20:51:35.065 ERR ] 20:51:35.066 ERR ZodError: [ 20:51:35.066 ERR { 20:51:35.066 ERR "code": "invalid_type", 20:51:35.066 ERR "expected": "object", 20:51:35.067 ERR "received": "undefined", 20:51:35.067 ERR "path": [], 20:51:35.067 ERR "message": "Required" 20:51:35.067 ERR } 20:51:35.067 ERR ] 20:51:35.067 ERR at o7 (/tmp/121f3729ba799437/node_modules/zod/lib/index.mjs:449:23) 20:51:35.067 ERR at Va.safeParse (/tmp/121f3729ba799437/node_modules/zod/lib/index.mjs:561:16) 20:51:35.067 ERR at Va.parse (/tmp/121f3729ba799437/node_modules/zod/lib/index.mjs:541:29) 20:51:35.067 ERR at Object.callback (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/classic/classic.ts:460:39) 20:51:35.067 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) 20:51:35.067 ERR at runMicrotasks (<anonymous>) 20:51:35.067 ERR at processTicksAndRejections (node:internal/process/task_queues:96:5) 20:51:35.068 ERR Error caught in "player.introDone" callback: 20:51:35.215 ERR TypeError: Cannot read properties of undefined (reading 'lobbyConfig') 20:51:35.216 ERR at D9.get lobbyConfig (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/classic/models.ts:168:24) 20:51:35.216 ERR at Object.callback (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/classic/lobby.ts:27:20) 20:51:35.216 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) 20:51:35.216 ERR at runMicrotasks (<anonymous>) 20:51:35.216 ERR at processTicksAndRejections (node:internal/process/task_queues:96:5) 20:51:35.216 ERR Error caught in "player.introDone" callback: 20:51:35.439 ERR TypeError: Cannot read properties of undefined (reading 'lobbyConfig') 20:51:35.439 ERR at D9.get lobbyConfig (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/classic/models.ts:168:24) 20:51:35.439 ERR at Object.callback (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/classic/lobby.ts:27:20) 20:51:35.439 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) 20:51:35.440 ERR at runMicrotasks (<anonymous>) 20:51:35.440 ERR at processTicksAndRejections (node:internal/process/task_queues:96:5) Batch 01HKX4MRJC97MYK2REC0JFBHH0 changed status to "running" 20:51:35.441 ERR Error caught in "batch.status" callback: 20:51:35.693 ERR TypeError: Cannot read properties of undefined (reading 'get') 20:51:35.693 ERR at Object.callback (/tmp/121f3729ba799437/src/callbacks.js:12:36) 20:51:35.693 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) 20:51:35.693 ERR at runMicrotasks (<anonymous>) 20:51:35.694 ERR at processTicksAndRejections (node:internal/process/task_queues:96:5) Batch 01HKX4BH1Q3BC4WDJ2GZHXWTCS changed status to "ended" 20:51:35.694 ERR Error caught in "batch.status" callback: 20:51:35.781 ERR TypeError: Cannot read properties of undefined (reading 'get') 20:51:35.781 ERR at Object.callback (/tmp/121f3729ba799437/src/callbacks.js:12:36) 20:51:35.782 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) 20:51:35.782 ERR at runMicrotasks (<anonymous>) 20:51:35.782 ERR at processTicksAndRejections (node:internal/process/task_queues:96:5) Batch 01HKX4MRJC97MYK2REC0JFBHH0 changed status to "running" management: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MDQ5ODM1MzUsImV4cCI6MTcwNTA2OTkzNSwianRpIjoiand0X25vbmNlIiwidHlwZSI6Im1hbmFnZW1lbnQiLCJ2ZXJzaW9uIjoyLCJuYmYiOjE3MDQ5ODM1MzUsImFjY2Vzc19rZXkiOiI2NTU5MTc2ODY4MTExZjZmZTRiNTdlNTcifQ.wV8CvHlNd3TtycnlcoT5HJkDOw4RgkApYFvuyWHDXSs templateID: 65591de4c75a69c5f81034f4 All rooms created, and all roomCodes set! Round 0 Batch 01HKX4MRJC97MYK2REC0JFBHH0 changed status to "terminated" 20:51:42.615 ERR Error caught in "batch.status" callback: 20:51:43.015 ERR TypeError: Cannot read properties of undefined (reading 'get') 20:51:43.016 ERR at Object.callback (/tmp/121f3729ba799437/src/callbacks.js:12:36) 20:51:43.016 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) Batch 01HKX4BH1Q3BC4WDJ2GZHXWTCS changed status to "ended" 20:51:43.017 ERR Error caught in "batch.status" callback: 20:51:43.231 ERR TypeError: Cannot read properties of undefined (reading 'get') 20:51:43.231 ERR at Object.callback (/tmp/121f3729ba799437/src/callbacks.js:12:36) 20:51:43.231 ERR at Object.next (/tmp/121f3729ba799437/node_modules/@empirica/core/src/admin/cake.ts:322:30) 20:51:43.232 INF server: started

npaton commented 4 months ago

I believe this is fixed in the latest releases.