fix(usbboot): handle LIBUSB_ERROR_NO_DEVICE when claiming a USB interface (#1796)

Consider the following scenario:

- Usbboot runs successfully on a device
- Before the block device gets a chance to appear, we run usbboot again

If we're fast enough, usbboot will try to claim the device interface,
but then the drive might not be there anymore, causing a
`LIBUSB_ERROR_NO_DEVICE`.

This commit addresses that scenario, and simply ignores the drive.

Change-Type: patch
Changelog-Entry: Fix `LIBUSB_ERROR_NO_DEVICE` error at the end of usbboot.
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
This commit is contained in:
Juan Cruz Viotti 2017-10-20 11:10:12 -04:00 committed by GitHub
parent 39e6207183
commit a11a22453a

View File

@ -400,7 +400,17 @@ exports.scan = (options) => {
const deviceInterface = device.interface(addresses.interface)
debug(`Claiming interface: ${addresses.interface}`)
deviceInterface.claim()
try {
deviceInterface.claim()
} catch (error) {
if (error.message === 'LIBUSB_ERROR_NO_DEVICE') {
debug('Couldn\'t claim the interface. Assuming the device is gone')
return null
}
throw error
}
const endpoint = deviceInterface.endpoint(addresses.endpoint)
@ -429,5 +439,5 @@ exports.scan = (options) => {
// See http://bluebirdjs.com/docs/api/promise.map.html
}, {
concurrency: 5
})
}).then(_.compact)
}