Avoid stack trace and Sentry report if user answers No to confirmation prompts

Change-type: patch
Signed-off-by: Paulo Castro <paulo@balena.io>
This commit is contained in:
Paulo Castro 2019-09-30 20:56:57 +01:00
parent d9b417e9e5
commit e0e76a1aa8
3 changed files with 13 additions and 12 deletions

View File

@ -99,17 +99,12 @@ export default class EnvRmCmd extends Command {
);
}
try {
await patterns.confirm(
options.yes || false,
'Are you sure you want to delete the environment variable?',
);
} catch (err) {
if (err.message === 'Aborted') {
return patterns.exitWithExpectedError(err);
}
throw err;
}
await patterns.confirm(
options.yes || false,
'Are you sure you want to delete the environment variable?',
undefined,
true,
);
await balena.pine.delete({
resource: options.device

View File

@ -393,6 +393,7 @@ exports.initialize =
options.yes
"This will erase #{answers.drive}. Are you sure?"
"Going to erase #{answers.drive}."
true
)
.return(answers.drive)
.then(umountAsync)

View File

@ -133,6 +133,7 @@ export function confirm(
yesOption: boolean,
message: string,
yesMessage?: string,
exitIfDeclined = false,
) {
return Bluebird.try(function() {
if (yesOption) {
@ -149,7 +150,11 @@ export function confirm(
});
}).then(function(confirmed) {
if (!confirmed) {
throw new Error('Aborted');
const err = new Error('Aborted');
if (exitIfDeclined) {
exitWithExpectedError(err);
}
throw err;
}
});
}