Skip to content

Fix crash when referencing non-existent target ref ID#128

Merged
albertyw merged 1 commit intouber:masterfrom
Nepomuk5665:fix-undefined-target-ref-crash
Jan 23, 2026
Merged

Fix crash when referencing non-existent target ref ID#128
albertyw merged 1 commit intouber:masterfrom
Nepomuk5665:fix-undefined-target-ref-crash

Conversation

@Nepomuk5665
Copy link
Copy Markdown
Contributor

Summary

  • Fixes a runtime crash (TypeError) when a graph target references a non-existent ref ID
  • Adds proper error handling with a descriptive error message
  • Adds test coverage for the fix

Problem

The handleRefTargets function in src/panels/graph.ts used Array.find() with a TypeScript non-null assertion (!) to look up target references by refId:

const findTargetByRefId = (targets: TargetObject[], refId: string) =>
    targets.find((target) => target.refId === refId)!.target;

When a target referenced a non-existent ref (e.g., #Z when only #A and #B exist), find() returned undefined and accessing .target on it caused:

TypeError: Cannot read property 'target' of undefined

Solution

Added explicit null checking with a descriptive error message that includes:

  • The invalid ref that was referenced
  • All available refs for easy debugging

Example error message:

Error: Invalid target reference: #Z does not exist. Available refs: A, B

Testing

  • Added a new test case that verifies the descriptive error is thrown
  • All existing tests pass

The handleRefTargets function used Array.find() with a non-null assertion
to look up target references by refId. When a non-existent ref was
referenced (e.g., #Z when only #A and #B exist), find() returned
undefined and accessing .target on it caused a runtime TypeError.

This change adds proper error handling to throw a descriptive error
message that includes the invalid ref and lists all available refs,
making debugging much easier for users.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 23, 2026

CLA assistant check
All committers have signed the CLA.

@albertyw albertyw merged commit be3d0e4 into uber:master Jan 23, 2026
7 checks passed
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.

3 participants