From 68f87435def2020fdc7c900f151d541fe34c9ba7 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 11 Apr 2017 00:59:08 -0400 Subject: [PATCH] fix(CLI): throw error if image is inaccessible (#1281) Consider the following scenario: - The user selects an image from an external drive - The user selects a drive - The user unmounts/ejects the external drive - The user clicks flash The application state will contain an image path that is no longer accessible, causing an ENOENT error when spawning the CLI process. Change-Type: patch Changelog-Entry: Display a user error if the image is no longer accessible when the writer starts. Signed-off-by: Juan Cruz Viotti --- lib/cli/options.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/cli/options.js b/lib/cli/options.js index 2d9b2c9a..e09e6939 100644 --- a/lib/cli/options.js +++ b/lib/cli/options.js @@ -107,7 +107,14 @@ module.exports = yargs // Assert that image exists .check((argv) => { - fs.accessSync(argv._[IMAGE_PATH_ARGV_INDEX]); + const imagePath = argv._[IMAGE_PATH_ARGV_INDEX]; + + try { + fs.accessSync(imagePath); + } catch (error) { + throw errors.createUserError('Unable to access file', `The image ${imagePath} is not accessible`); + } + return true; })