mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Merge pull request #2117 from balena-io/add_device_deactivation_expected_errors
errors: Add expected errors for device deactivation
This commit is contained in:
commit
659eda8cd1
@ -71,15 +71,16 @@ export default class DeviceDeactivateCmd extends Command {
|
||||
|
||||
const uuid = params.uuid;
|
||||
const deactivationWarning = `
|
||||
|
||||
Warning! Deactivating a device will charge a fee equivalent to the
|
||||
normal monthly cost for the device (e.g. $1 for an essentials device);
|
||||
the device will not be charged again until it comes online.
|
||||
`;
|
||||
|
||||
Are you sure you want to deactivate device ${uuid} ?`;
|
||||
const warning = `Are you sure you want to deactivate device ${uuid} ?`;
|
||||
|
||||
console.error(deactivationWarning);
|
||||
// Confirm
|
||||
await patterns.confirm(options.yes, deactivationWarning);
|
||||
await patterns.confirm(options.yes, warning);
|
||||
// Deactivate
|
||||
await balena.models.device.deactivate(uuid);
|
||||
}
|
||||
|
@ -142,6 +142,9 @@ const messages: {
|
||||
Try logging in again with the "balena login" command.`,
|
||||
};
|
||||
|
||||
// TODO remove these regexes when we have a way of uniquely indentifying errors.
|
||||
// related issue https://github.com/balena-io/balena-sdk/issues/1025
|
||||
// related issue https://github.com/balena-io/balena-cli/issues/2126
|
||||
const EXPECTED_ERROR_REGEXES = [
|
||||
/^BalenaAmbiguousApplication/, // balena-sdk
|
||||
/^BalenaAmbiguousDevice/, // balena-sdk
|
||||
@ -149,6 +152,8 @@ const EXPECTED_ERROR_REGEXES = [
|
||||
/^BalenaDeviceNotFound/, // balena-sdk
|
||||
/^BalenaExpiredToken/, // balena-sdk
|
||||
/^BalenaInvalidDeviceType/, // balena-sdk
|
||||
/Cannot deactivate devices/i, // balena-api
|
||||
/Devices must be offline in order to be deactivated\.$/i, // balena-api
|
||||
/Request error: Unauthorized$/, // balena-sdk
|
||||
/^Missing \d+ required arg/, // oclif parser: RequiredArgsError
|
||||
/Missing required flag/, // oclif parser: RequiredFlagError
|
||||
|
@ -25,6 +25,7 @@ import {
|
||||
import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy';
|
||||
import validation = require('./validation');
|
||||
import { delay } from './helpers';
|
||||
import { isV13 } from './version';
|
||||
|
||||
export function authenticate(options: {}): Promise<void> {
|
||||
const balena = getBalenaSdk();
|
||||
@ -147,7 +148,11 @@ export async function confirm(
|
||||
) {
|
||||
if (yesOption) {
|
||||
if (yesMessage) {
|
||||
console.log(yesMessage);
|
||||
if (isV13()) {
|
||||
console.error(yesMessage);
|
||||
} else {
|
||||
console.log(yesMessage);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -159,7 +164,8 @@ export async function confirm(
|
||||
});
|
||||
|
||||
if (!confirmed) {
|
||||
const err = new Error('Aborted');
|
||||
const err = new ExpectedError('Aborted');
|
||||
// TODO remove this deprecated function (exitWithExpectedError)
|
||||
if (exitIfDeclined) {
|
||||
exitWithExpectedError(err);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user