mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-21 09:51:58 +00:00
Fix handling of BalenaExpiredToken error
Change-type: patch Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
parent
a85c482416
commit
555096db6b
@ -135,10 +135,10 @@ const messages: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const EXPECTED_ERROR_REGEXES = [
|
const EXPECTED_ERROR_REGEXES = [
|
||||||
/^BalenaAmbiguousApplication:/, // balena-sdk
|
/^BalenaAmbiguousApplication/, // balena-sdk
|
||||||
/^BalenaApplicationNotFound:/, // balena-sdk
|
/^BalenaApplicationNotFound/, // balena-sdk
|
||||||
/^BalenaDeviceNotFound:/, // balena-sdk
|
/^BalenaDeviceNotFound/, // balena-sdk
|
||||||
/^BalenaExpiredToken:/, // balena-sdk
|
/^BalenaExpiredToken/, // balena-sdk
|
||||||
/^Missing \w+$/, // Capitano, oclif parser: RequiredArgsError, RequiredFlagError
|
/^Missing \w+$/, // Capitano, oclif parser: RequiredArgsError, RequiredFlagError
|
||||||
/^Unexpected argument/, // oclif parser: UnexpectedArgsError
|
/^Unexpected argument/, // oclif parser: UnexpectedArgsError
|
||||||
/to be one of/, // oclif parser: FlagInvalidOptionError, ArgInvalidOptionError
|
/to be one of/, // oclif parser: FlagInvalidOptionError, ArgInvalidOptionError
|
||||||
@ -172,7 +172,8 @@ export async function handleError(error: any) {
|
|||||||
// Expected?
|
// Expected?
|
||||||
const isExpectedError =
|
const isExpectedError =
|
||||||
error instanceof ExpectedError ||
|
error instanceof ExpectedError ||
|
||||||
EXPECTED_ERROR_REGEXES.some(re => re.test(message[0]));
|
EXPECTED_ERROR_REGEXES.some(re => re.test(message[0])) ||
|
||||||
|
EXPECTED_ERROR_REGEXES.some(re => re.test((error as any).code));
|
||||||
|
|
||||||
// Output/report error
|
// Output/report error
|
||||||
if (isExpectedError) {
|
if (isExpectedError) {
|
||||||
|
@ -15,6 +15,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
BalenaAmbiguousApplication,
|
||||||
|
BalenaApplicationNotFound,
|
||||||
|
BalenaDeviceNotFound,
|
||||||
|
BalenaExpiredToken,
|
||||||
|
} from 'balena-errors';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as sinon from 'sinon';
|
import * as sinon from 'sinon';
|
||||||
import ErrorsModule from '../build/errors';
|
import ErrorsModule from '../build/errors';
|
||||||
@ -124,10 +130,6 @@ describe('handleError() function', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const messagesToMatch = [
|
const messagesToMatch = [
|
||||||
'BalenaAmbiguousApplication:',
|
|
||||||
'BalenaApplicationNotFound:',
|
|
||||||
'BalenaDeviceNotFound:',
|
|
||||||
'BalenaExpiredToken:',
|
|
||||||
'Missing argument',
|
'Missing argument',
|
||||||
'Missing arguments',
|
'Missing arguments',
|
||||||
'Unexpected argument',
|
'Unexpected argument',
|
||||||
@ -149,6 +151,25 @@ describe('handleError() function', () => {
|
|||||||
expect(processExit.notCalled).to.be.true;
|
expect(processExit.notCalled).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const typedErrorsToMatch = [
|
||||||
|
new BalenaAmbiguousApplication('test'),
|
||||||
|
new BalenaApplicationNotFound('test'),
|
||||||
|
new BalenaDeviceNotFound('test'),
|
||||||
|
new BalenaExpiredToken('test'),
|
||||||
|
];
|
||||||
|
|
||||||
|
typedErrorsToMatch.forEach(typedError => {
|
||||||
|
it(`should treat typedError ${typedError.name} as expected`, async () => {
|
||||||
|
await ErrorsModule.handleError(typedError);
|
||||||
|
|
||||||
|
expect(printExpectedErrorMessage.calledOnce).to.be.true;
|
||||||
|
|
||||||
|
expect(printErrorMessage.notCalled).to.be.true;
|
||||||
|
expect(captureException.notCalled).to.be.true;
|
||||||
|
expect(processExit.notCalled).to.be.true;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('printErrorMessage() function', () => {
|
describe('printErrorMessage() function', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user