fix(core): guard material-ref parsers against non-string values (Sentry MONOREPO-EDITOR-EM)#486
Merged
Conversation
…ry MONOREPO-EDITOR-EM) getLibraryMaterialIdFromRef and getSceneMaterialIdFromRef only guarded against null/undefined, then called .startsWith(). When a non-string material ref reaches them (legacy/malformed wall material slot ref), .startsWith is undefined -> TypeError: e.startsWith is not a function. Narrow with typeof !== 'string' -> return null, so a bad ref degrades to 'no library/scene material' instead of throwing during wall material resolution (packages/viewer wall-materials.ts -> parseMaterialRef).
Contributor
Author
|
Nightly Sentry triage 2026-07-14: MONOREPO-EDITOR-EM is still firing in production (latest event 2026-07-14 01:57 UTC, release 4473110, editor.pascal.app). Confirmed the in-app stack matches this PR's target: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add a
typeof materialRef !== 'string'guard togetLibraryMaterialIdFromRefandgetSceneMaterialIdFromRefinpackages/core/src/material-library.ts.Why
Both functions only guarded against null/undefined before calling
.startsWith():When a non-string material ref reaches them (a legacy or malformed wall material slot ref),
.startsWithis undefined ->TypeError: e.startsWith is not a function.Stack originates in wall material resolution:
packages/viewer/src/systems/wall/wall-materials.ts->parseMaterialRef(ref)->getLibraryMaterialIdFromRef.Safety
typeof x !== 'string'narrows tostring, so.startsWith/.sliceremain valid; return type unchanged (non-string already mapped tonull). Behaviour for real string refs is identical.Verification
tsc --noEmiton @pascal-app/core: exit 0. biome check: clean.Opened by nightly Sentry triage. Do not auto-merge - review first.
Note
Low Risk
Narrow defensive change in ref parsing; string behavior is unchanged and failures degrade to null like other invalid refs.
Overview
Hardens library and scene material ref parsing so malformed runtime values (numbers, booleans, objects) return
nullinstead of throwing when.startsWithis invoked.getLibraryMaterialIdFromRefandgetSceneMaterialIdFromRefnow bail out withtypeof materialRef !== 'string'before prefix checks; scene parsing no longer relies on optional chaining alone on a possibly non-string ref. Valid string refs behave the same.Adds a small Bun test that asserts both helpers return
nullfor common non-string inputs, covering the wall material path that goes throughparseMaterialRef.Reviewed by Cursor Bugbot for commit 4b770d0. Bugbot is set up for automated code reviews on this repo. Configure here.