Skip to content

Commit

Permalink
Add optional chaining to prevent undefined platofmr access
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jan 8, 2025
1 parent 1914154 commit d1ac0d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/device-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,10 @@ async function getDevices({ types = [], includeDfu = true } = {}) {
const filters = [];
PLATFORMS.forEach((platform) => {
if (types.length === 0 || types.includes(platform.name)) {
if (platform.usb.vendorId) {
if (platform?.usb?.vendorId) {
filters.push(platform.usb);
}
if (includeDfu && platform.dfu.vendorId) {
if (includeDfu && platform?.dfu?.vendorId) {
filters.push(platform.dfu);
}
}
Expand All @@ -765,10 +765,10 @@ async function openDeviceById(id, options = null) {
const log = globalOptions.log;
const filters = [];
PLATFORMS.forEach((platform) => {
if (platform.usb.vendorId) {
if (platform?.usb?.vendorId) {
filters.push(Object.assign({ serialNumber: id }, platform.usb));
}
if (platform.dfu.vendorId) {
if (platform?.dfu?.vendorId) {
filters.push(Object.assign({ serialNumber: id }, platform.dfu));
}
});
Expand Down
8 changes: 4 additions & 4 deletions test/support/fake-usb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ const USB_DEVICES = PLATFORMS.reduce((arr, platform) => {
arr.push({
type: platform.name,
platformId: platform.id,
vendorId: platform.usb.vendorId,
productId: platform.usb.productId,
vendorId: platform?.usb?.vendorId,
productId: platform?.usb?.productId,
dfu: false
});
}
if (platform.dfu) {
arr.push({
type: platform.name,
platformId: platform.id,
vendorId: platform.dfu.vendorId,
productId: platform.dfu.productId,
vendorId: platform?.dfu?.vendorId,
productId: platform?.dfu?.productId,
dfu: true
});
}
Expand Down

0 comments on commit d1ac0d4

Please sign in to comment.