os download: Improve error message for misspelled device type names

Change-type: patch
This commit is contained in:
Paulo Castro 2021-07-23 14:40:44 +01:00
parent 918c2e912d
commit 8338e2e933
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.