From 88ef2359874c0dceacf7f7de4ced39ae6fc311ce Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 20 Oct 2017 08:50:58 -0400 Subject: [PATCH] fix(usbboot): handle device disconnections (#1798) This commit handles errors that can come up when unplugging the drive halfway through the process. After tons of experimentation, the errors than seem to occur are: - `LIBUSB_TRANSFER_CANCELLED` - `LIBUSB_ERROR_NO_DEVICE` When these errors happen, we can omit the drive, and also not try to close it, since given the device is no longer there, the close operation bails out with a strange error message. Change-Type: patch Changelog-Entry: Gracefully handle scenarios where a USB drive is disconnected halfway through the usbboot procedure. Signed-off-by: Juan Cruz Viotti --- lib/shared/sdk/usbboot/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/shared/sdk/usbboot/index.js b/lib/shared/sdk/usbboot/index.js index bc79a1c3..fd8a4ac5 100644 --- a/lib/shared/sdk/usbboot/index.js +++ b/lib/shared/sdk/usbboot/index.js @@ -376,8 +376,14 @@ exports.scan = (options) => { debug('Starting file server') return startFileServer(device, endpoint, options.files) - }).return(device).finally(() => { - device.close() + }).return(device).catch({ + message: 'LIBUSB_TRANSFER_CANCELLED' + }, { + message: 'LIBUSB_ERROR_NO_DEVICE' + }, _.constant(null)).tap((result) => { + if (result) { + result.close() + } }) // See http://bluebirdjs.com/docs/api/promise.map.html