Guard getResourceStatuses against a null resource#2566
Conversation
getResourceStatuses already tolerates a missing resource (const {executions=[]}
= resource || {}, resource?.is_approved, resource?.is_published) but then
dereferenced resource.advertised directly, throwing TypeError on null. Use
resource?.advertised to complete the existing null handling.
Adds a test in ResourceUtils-test.js; getResourceStatuses(null) throws on
master and returns the expected status object with the fix.
There was a problem hiding this comment.
Code Review
This pull request introduces optional chaining (resource?.advertised) in the getResourceStatuses utility function to prevent potential runtime errors when the resource parameter is null or undefined. Additionally, a unit test has been added to verify that the function handles a null resource gracefully and returns the expected default statuses. There are no review comments to address, and the changes look correct and well-tested.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Problem
getResourceStatuses(resource, userInfo)inutils/ResourceUtils.jsis written to tolerate a missing resource — it guards three reads:…but then dereferences
resourcewithout a guard:So
getResourceStatuses(null)(orundefined) throwsTypeError: Cannot read properties of null (reading 'advertised'), defeating the null-handling the rest of the function already implements.Fix
Test
Added to
utils/__tests__/ResourceUtils-test.js:getResourceStatuses(null)throws onmasterand returns the expected status object (isProcessing/isDeleting/isCopying: false,items: []) with the fix. Full suite green.