fix(Cornerstone): guard volume validation when metadata is unavailable#6093
fix(Cornerstone): guard volume validation when metadata is unavailable#6093WillianVarela wants to merge 3 commits into
Conversation
✅ Deploy Preview for ohif-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughFixes a typo in ChangesImage ID Handling and Volume Validation Fixes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@extensions/cornerstone/src/components/ViewportDataOverlaySettingMenu/utils.ts`:
- Around line 8-12: In the getImageIdsFromDisplaySet function, add optional
chaining when accessing the imageId property on array elements to prevent
potential errors if null or undefined elements exist in the arrays.
Specifically, update the map operations for both the images array and instances
array to use optional chaining (image?.imageId and instance?.imageId) instead of
direct property access (image.imageId and instance.imageId). This ensures the
function remains defensive and won't throw if array elements are null or
undefined.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 14233cb8-db8d-481d-bb7b-3e4e5510c1d2
📒 Files selected for processing (2)
extensions/cornerstone/src/components/ViewportDataOverlaySettingMenu/utils.tsextensions/cornerstone/src/services/CornerstoneCacheService/CornerstoneCacheService.ts
…ngMenu/utils.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…ngMenu/utils.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Context
When opening some multi-frame DICOM studies from JSON metadata, the viewport overlay/rendering controls can crash while evaluating overlay display sets.
The crash happens in
getEnhancedDisplaySetswhencsUtils.isValidVolume(imageIds)is called before Cornerstone metadata is available for one or more imageIds.Example error:
This can happen during viewport initialization, where the display set already has imageIds but the metadata provider is not ready for all of them yet.
Fixes #5680
Fixes #5909
Changes & Results
csUtils.isValidVolume.falsewhen there are no imageIds or when volume validation throws because metadata is unavailable.CornerstoneCacheServicewhere stack image IDs were assigned toimagesIdsinstead ofimageIds.Before:
isValidVolumetried to read missing metadata.After:
Testing
Tested locally with a multi-frame DICOM study loaded from JSON metadata.
Also ran:
The extension build completed successfully.
Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
No public API additions or removals were made.
Tested Environment
Summary by CodeRabbit
Greptile Summary
This PR guards against a crash in
getEnhancedDisplaySetswhen Cornerstone metadata is not yet available for all imageIds during viewport initialization, and fixes a typo inCornerstoneCacheServicethat silently wrote stack image IDs to the wrong property name.isValidVolumeDisplaySet, a try/catch wrapper aroundcsUtils.isValidVolumethat returnsfalse(with aconsole.warn) instead of crashing when metadata is absent; both background and foreground volume checks now use it.getImageIdsFromDisplaySetto normalize imageId extraction across the three display set shapes (imageIds,images[].imageId,instances[].imageId), always returning at least[].imagesIds→imageIdstypo inCornerstoneCacheService._getOtherViewportDataso thatdisplaySet.imageIdsis actually populated and readable by downstream consumers.Confidence Score: 5/5
Safe to merge — both changes are narrowly scoped defensive fixes with no behavioural regressions on the happy path.
The crash guard in
isValidVolumeDisplaySetonly activates whencsUtils.isValidVolumethrows or receives an empty array, leaving normal execution unchanged. The typo fix inCornerstoneCacheServicecorrects a silent no-op assignment so thatdisplaySet.imageIdsis correctly populated; the return value shape of the function is unaffected. No new logic branches, no API surface changes, and the previous review concern about silent swallowing was already addressed with aconsole.warn.No files require special attention.
Important Files Changed
getImageIdsFromDisplaySetandisValidVolumeDisplaySethelpers to guard against crashes when metadata is unavailable; replaces directcsUtils.isValidVolumecalls with the safe wrapper throughoutgetEnhancedDisplaySets.imagesIds→imageIdsso the populated property is actually readable by downstream consumers viadisplaySet.imageIds.Reviews (2): Last reviewed commit: "Update extensions/cornerstone/src/compon..." | Re-trigger Greptile