Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.115.0
- OS Version: Windows 11
Steps to Reproduce:
-
Open chatModelSelectionLogic.ts
-
Locate the findDefaultModel function
-
Observe the following line:
return models.find(m => m.metadata.isDefaultForLocation[location]) || models[0];
-
Notice that isDefaultForLocation is accessed without null/undefined checks
Expected Behavior:
Access to nested properties like isDefaultForLocation should be safe (e.g., using optional chaining) to prevent potential runtime errors when metadata is incomplete or comes from external sources.
Actual Behavior:
The code assumes m.metadata.isDefaultForLocation is always defined.
If it is undefined for any model, this may throw a runtime error:
Cannot read properties of undefined
Additional Information:
Since models can be contributed by external providers, metadata fields may not always be guaranteed. Other parts of the codebase use optional chaining (?.) for similar cases.
Suggested fix:
m.metadata.isDefaultForLocation?.[location]
Additionally, models[0] is used as a fallback without checking if the array is empty, which may lead to unintended undefined returns.
Does this issue occur when all extensions are disabled?: Yes
Steps to Reproduce:
Open
chatModelSelectionLogic.tsLocate the
findDefaultModelfunctionObserve the following line:
Notice that
isDefaultForLocationis accessed without null/undefined checksExpected Behavior:
Access to nested properties like
isDefaultForLocationshould be safe (e.g., using optional chaining) to prevent potential runtime errors when metadata is incomplete or comes from external sources.Actual Behavior:
The code assumes
m.metadata.isDefaultForLocationis always defined.If it is undefined for any model, this may throw a runtime error:
Additional Information:
Since models can be contributed by external providers, metadata fields may not always be guaranteed. Other parts of the codebase use optional chaining (
?.) for similar cases.Suggested fix:
Additionally,
models[0]is used as a fallback without checking if the array is empty, which may lead to unintended undefined returns.