Completing a series instrument logs a TypeError "Cannot read properties of undefined (reading 'kind')"
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
Start with packages/react-core/src/components/InstrumentRenderer/SeriesInstrumentRenderer.tsx, where the item index reaches items.length and an empty bundle is passed on, then read packages/react-core/src/hooks/useInterpretedInstrument.ts and packages/instrument-interpreter/src/index.ts to see where the raw TypeError escapes the try block. Reproduce by completing a series in the playground and watching the console. Done means a finished series logs no error, and an invalid bundle produces the normal evaluation error.
Written by the indexing model from the issue text.
Description
Problem
When a subject completes the last item of a series instrument, the browser console shows an error:
TypeError: Cannot read properties of undefined (reading 'kind')
The UI is correct (the "Thank You" screen shows), but each completed series logs this error. The error is noise and can hide real errors.
Cause
- After the last item is submitted, the submit handler increments the item index to
items.length:
https://github.com/DouglasNeuroInformatics/OpenDataCapture/blob/432dec8115722d8316922f0069f0c3b67f09214a/packages/react-core/src/components/InstrumentRenderer/SeriesInstrumentRenderer.tsx#L115 - The scalar bundle is then
undefined, and the renderer passes an empty string to the hook:
https://github.com/DouglasNeuroInformatics/OpenDataCapture/blob/432dec8115722d8316922f0069f0c3b67f09214a/packages/react-core/src/components/InstrumentRenderer/SeriesInstrumentRenderer.tsx#L65-L69 - The hook interprets every bundle, including
'', and logs every rejection withconsole.error:
https://github.com/DouglasNeuroInformatics/OpenDataCapture/blob/432dec8115722d8316922f0069f0c3b67f09214a/packages/react-core/src/hooks/useInterpretedInstrument.ts#L30-L54 evaluateInstrument('')runsnew Function('return ')(), which returnsundefined:
https://github.com/DouglasNeuroInformatics/OpenDataCapture/blob/432dec8115722d8316922f0069f0c3b67f09214a/packages/runtime-internal/src/index.js#L3- Without
validate, thetryblock does not throw. Theinstrument.kindaccess is outside thetry, so it throws a rawTypeError:
https://github.com/DouglasNeuroInformatics/OpenDataCapture/blob/432dec8115722d8316922f0069f0c3b67f09214a/packages/instrument-interpreter/src/index.ts#L18-L30
A series that ends through terminate does not have this problem, because the handler returns before it increments the index.
Steps to reproduce
- Open a series instrument (for example, in the playground or as a remote assignment).
- Complete all items.
- Open the browser console.
Expected: No error.
Actual: One TypeError: Cannot read properties of undefined (reading 'kind') is logged.
Suggested fix
- In
useInterpretedInstrument, do not interpret an empty bundle (or let the hook acceptnulland skip the effect). Or, inSeriesInstrumentRenderer, do not request a scalar instrument whencurrentItemIndex >= target.items.length. - Also, in
InstrumentInterpreter.interpret, reject a non-object result inside thetryblock, so that a bad bundle gives the normal "Failed to evaluate instrument bundle" error and not a rawTypeError.
cc @joshunrau (last change to these files)
- Dominant language
- TypeScript
- Stars
- 119
- Forks
- 19
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 44
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DouglasNeuroInformatics/OpenDataCapture
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
DouglasNeuroInformatics/OpenDataCapture#1812 ·
Maintainers usually reply within 1 day
-
Area: Playground Bug Difficulty: Low Good First Issue Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
DouglasNeuroInformatics/OpenDataCapture#1805 ·
Maintainers usually reply within 1 day
-
Area: Instruments Bug Difficulty: Low Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
DouglasNeuroInformatics/OpenDataCapture#1801 ·
Maintainers usually reply within 1 day
-
Area: Instruments Bug Difficulty: Low Good First Issue Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
DouglasNeuroInformatics/OpenDataCapture#1800 ·
Maintainers usually reply within 1 day
-
Area: Instruments Bug Difficulty: Low Good First Issue Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
DouglasNeuroInformatics/OpenDataCapture#1799 ·
Maintainers usually reply within 1 day
All issues in DouglasNeuroInformatics/OpenDataCapture
Similar issues
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 90/100
lingdojo/kana-dojo#32663 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day
-
Admin: Title Separator field can't be cleared (input falls back to "|")Possibly taken @emdashbot claimed this today. Openbot:bug bot:in-review
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
emdash-cms/emdash#4236 · 3 comments ·
Maintainers usually reply within 1 day
-
PHP workflow streaming requests buffer the full SSE responsePossibly taken @Winoren claimed this today. Openreview: medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
langgenius/dify#44270 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
area:holodeck review-finding
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
hyperdrive-technology/holodeck#142 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
code-yeongyu/senpi#3573 ·
Maintainers usually reply within 1 day