Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Completing a series instrument logs a TypeError "Cannot read properties of undefined (reading 'kind')"

Open Beginner friendly
#1,813 0 comments 0 reactions 0 assignees View on GitHub

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

  1. 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
  2. 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
  3. The hook interprets every bundle, including '', and logs every rejection with console.error:
    https://github.com/DouglasNeuroInformatics/OpenDataCapture/blob/432dec8115722d8316922f0069f0c3b67f09214a/packages/react-core/src/hooks/useInterpretedInstrument.ts#L30-L54
  4. evaluateInstrument('') runs new Function('return ')(), which returns undefined:
    https://github.com/DouglasNeuroInformatics/OpenDataCapture/blob/432dec8115722d8316922f0069f0c3b67f09214a/packages/runtime-internal/src/index.js#L3
  5. Without validate, the try block does not throw. The instrument.kind access is outside the try, so it throws a raw TypeError:
    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

  1. Open a series instrument (for example, in the playground or as a remote assignment).
  2. Complete all items.
  3. 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 accept null and skip the effect). Or, in SeriesInstrumentRenderer, do not request a scalar instrument when currentItemIndex >= target.items.length.
  • Also, in InstrumentInterpreter.interpret, reject a non-object result inside the try block, so that a bad bundle gives the normal "Failed to evaluate instrument bundle" error and not a raw TypeError.

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DouglasNeuroInformatics/OpenDataCapture

All issues in DouglasNeuroInformatics/OpenDataCapture

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.