mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-23 23:42:24 +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 uuid = params.uuid;
|
||||||
const deactivationWarning = `
|
const deactivationWarning = `
|
||||||
|
|
||||||
Warning! Deactivating a device will charge a fee equivalent to the
|
Warning! Deactivating a device will charge a fee equivalent to the
|
||||||
normal monthly cost for the device (e.g. $1 for an essentials device);
|
normal monthly cost for the device (e.g. $1 for an essentials device);
|
||||||
the device will not be charged again until it comes online.
|
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
|
// Confirm
|
||||||
await patterns.confirm(options.yes, deactivationWarning);
|
await patterns.confirm(options.yes, warning);
|
||||||
// Deactivate
|
// Deactivate
|
||||||
await balena.models.device.deactivate(uuid);
|
await balena.models.device.deactivate(uuid);
|
||||||
}
|
}
|
||||||
|
@ -142,6 +142,9 @@ const messages: {
|
|||||||
Try logging in again with the "balena login" command.`,
|
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 = [
|
const EXPECTED_ERROR_REGEXES = [
|
||||||
/^BalenaAmbiguousApplication/, // balena-sdk
|
/^BalenaAmbiguousApplication/, // balena-sdk
|
||||||
/^BalenaAmbiguousDevice/, // balena-sdk
|
/^BalenaAmbiguousDevice/, // balena-sdk
|
||||||
@ -149,6 +152,8 @@ const EXPECTED_ERROR_REGEXES = [
|
|||||||
/^BalenaDeviceNotFound/, // balena-sdk
|
/^BalenaDeviceNotFound/, // balena-sdk
|
||||||
/^BalenaExpiredToken/, // balena-sdk
|
/^BalenaExpiredToken/, // balena-sdk
|
||||||
/^BalenaInvalidDeviceType/, // 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
|
/Request error: Unauthorized$/, // balena-sdk
|
||||||
/^Missing \d+ required arg/, // oclif parser: RequiredArgsError
|
/^Missing \d+ required arg/, // oclif parser: RequiredArgsError
|
||||||
/Missing required flag/, // oclif parser: RequiredFlagError
|
/Missing required flag/, // oclif parser: RequiredFlagError
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy';
|
import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy';
|
||||||
import validation = require('./validation');
|
import validation = require('./validation');
|
||||||
import { delay } from './helpers';
|
import { delay } from './helpers';
|
||||||
|
import { isV13 } from './version';
|
||||||
|
|
||||||
export function authenticate(options: {}): Promise<void> {
|
export function authenticate(options: {}): Promise<void> {
|
||||||
const balena = getBalenaSdk();
|
const balena = getBalenaSdk();
|
||||||
@ -147,8 +148,12 @@ export async function confirm(
|
|||||||
) {
|
) {
|
||||||
if (yesOption) {
|
if (yesOption) {
|
||||||
if (yesMessage) {
|
if (yesMessage) {
|
||||||
|
if (isV13()) {
|
||||||
|
console.error(yesMessage);
|
||||||
|
} else {
|
||||||
console.log(yesMessage);
|
console.log(yesMessage);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +164,8 @@ export async function confirm(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
const err = new Error('Aborted');
|
const err = new ExpectedError('Aborted');
|
||||||
|
// TODO remove this deprecated function (exitWithExpectedError)
|
||||||
if (exitIfDeclined) {
|
if (exitIfDeclined) {
|
||||||
exitWithExpectedError(err);
|
exitWithExpectedError(err);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user