Skip to content

Guard against undefined events in getAllEvents and identifyData#991

Closed
ioxde wants to merge 2 commits intocodama-idl:mainfrom
ioxde:fix/guard-undefined-events
Closed

Guard against undefined events in getAllEvents and identifyData#991
ioxde wants to merge 2 commits intocodama-idl:mainfrom
ioxde:fix/guard-undefined-events

Conversation

@ioxde
Copy link
Copy Markdown

@ioxde ioxde commented Apr 11, 2026

I ran into this issue after rebasing my fork to 35516d4. If you want me to merge the commits into one let me know.

getAllEvents returns [undefined] and identifyData throws when program.events is undefined. ProgramNodes from JSON deserialization or pre-events codama trees won't have the field.

The visitors already guard with (node.events ?? []) but I also added tests for them.

NOTE: Same gap exists in all getAll* functions. They all do bare program.X without ?? [].

I think the root cause is rootNode(). It passes programs through without calling programNode(), so raw JSON objects keep undefined for missing fields like events. The ?? [] guards are the safe incremental fix. A deeper fix would be normalizing through programNode() in rootNode(), but unsure if that has side-effects

Happy to update this PR if you want

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 11, 2026

🦋 Changeset detected

Latest commit: 33290af

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@codama/nodes Patch
@codama/dynamic-parsers Patch
@codama/cli Patch
@codama/dynamic-codecs Patch
codama Patch
@codama/nodes-from-anchor Patch
@codama/renderers-core Patch
@codama/validators Patch
@codama/visitors-core Patch
@codama/visitors Patch
@codama/errors Patch
@codama/node-types Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ioxde
Copy link
Copy Markdown
Author

ioxde commented Apr 12, 2026

I ran into this issue again even with these changes. I think the correct fix is either normalizing the data structure as mentioned above or changing the events type to readonly events?: TEvents; so it is correctly typed and callers will know.

Closing this- let me know if you'd like me to follow up with a different PR.

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 this pull request may close these issues.

1 participant