Guard required_ext access in validateFileResourceUploads (fixes TypeError for optional-only types)#2561
Conversation
validateFileResourceUploads dereferenced currentSupportedType.required_ext directly, but the field is optional in the data model — getSupportedTypeExt already guards it with || []. A supported type declaring only optional_ext matched the upload and then threw 'TypeError: Cannot read properties of undefined (reading includes)'. Guard the three required_ext reads with || [] to match getSupportedTypeExt. Adds a regression test (optional_ext-only type) that fails on the previous code with the TypeError and passes after the guard. Full suite: 340 tests.
There was a problem hiding this comment.
Code Review
This pull request fixes a potential TypeError in validateFileResourceUploads by safely guarding currentSupportedType.required_ext with a fallback empty array when it is undefined, and adds a corresponding regression test. The reviewer suggested refactoring the code to extract the repeated fallback expressions for required and optional extensions into local variables to improve readability and reduce redundancy.
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.
…esourceUploads Per review: replace the repeated '|| []' fallbacks with two locals (requiredExtensions, optionalExtensions) for readability. No behavior change; full suite still 340 tests.
|
Applied in dc8bd3b — extracted |
Problem
validateFileResourceUploadsdereferencescurrentSupportedType.required_extdirectly:But
required_extis optional in the data model —getSupportedTypeExtalready guards it:A
supportedTypedeclaring onlyoptional_ext(norequired_ext) still matches an upload viagetSupportedTypeExt, thenvalidateFileResourceUploadsthrowsTypeError: Cannot read properties of undefined (reading 'includes').(Originally raised by
gemini-code-assiston #2560; that PR only reindented these lines, so the fix belongs in its own change.)Fix
Guard the three
required_extreads with|| [], matchinggetSupportedTypeExt. No behavior change for types that declarerequired_ext.Test
Added a regression test in
UploadUtils-test.jsfor a supported type with onlyoptional_ext. It throws onmasterand passes with the fix:Full suite: 340 tests pass (was 339), Node 20.
Note
Touches the same
validateFileResourceUploadslines as #2560 (a CI lint-gate PR that reindented this file). The two are independent; whichever merges second needs a trivial whitespace rebase.