From 3bb157761c56e7eb2e1835914a98e2f1a9abf058 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Mon, 17 Oct 2022 23:46:49 +0300 Subject: [PATCH] Error when the device type and image parameters do not match Resolves: #2537 Change-type: patch Signed-off-by: Thodoris Greasidis --- lib/utils/helpers.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index d9e7d2a1e6..41be4db898 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -107,11 +107,21 @@ export async function getManifest( deviceType: string, ): Promise { const init = await import('balena-device-init'); + const sdk = getBalenaSdk(); const manifest = await init.getImageManifest(image); - if (manifest != null) { - return manifest; + if (manifest == null) { + return await sdk.models.device.getManifestBySlug(deviceType); + } + if ( + manifest.slug !== deviceType && + manifest.slug !== (await sdk.models.deviceType.get(deviceType)).slug + ) { + const { ExpectedError } = await import('../errors'); + throw new ExpectedError( + `The device type of the provided OS image ${manifest.slug}, does not match the expected device type ${deviceType}`, + ); } - return getBalenaSdk().models.device.getManifestBySlug(deviceType); + return manifest; } export const areDeviceTypesCompatible = async (