Merge pull request #2299 from balena-io/catch-BalenaInvalidDeviceType

os download: Improve error message for misspelled device type names
This commit is contained in:
bulldozer-balena[bot] 2021-07-23 14:53:22 +00:00 committed by GitHub
commit 3717d8cc0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -95,6 +95,11 @@ export default class OsDownloadCmd extends Command {
const { downloadOSImage } = await import('../../utils/cloud');
await downloadOSImage(params.type, options.output, options.version);
try {
await downloadOSImage(params.type, options.output, options.version);
} catch (e) {
e.deviceTypeSlug = params.type;
throw e;
}
}
}

View File

@ -174,6 +174,13 @@ const messages: {
BalenaExpiredToken: () => stripIndent`
Looks like the session token has expired.
Try logging in again with the "balena login" command.`,
BalenaInvalidDeviceType: (error: Error & { deviceTypeSlug?: string }) => {
const slug = error.deviceTypeSlug ? `"${error.deviceTypeSlug}"` : 'slug';
return stripIndent`
Device type ${slug} not recognized. Perhaps misspelled?
Check available device types with "balena devices supported"`;
},
};
// TODO remove these regexes when we have a way of uniquely indentifying errors.