Skip to content

Commit

Permalink
Error when the device type and image parameters do not match
Browse files Browse the repository at this point in the history
Resolves: #2537
Change-type: patch
Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
  • Loading branch information
thgreasi authored and ab77 committed Nov 10, 2022
1 parent ac3ebff commit 13edfe7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,19 @@ export async function getManifest(
deviceType: string,
): Promise<BalenaSdk.DeviceTypeJson.DeviceType> {
const init = await import('balena-device-init');
const sdk = getBalenaSdk();
const manifest = await init.getImageManifest(image);
if (manifest != null) {
return manifest;
if (
manifest != null &&
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 ?? (await sdk.models.device.getManifestBySlug(deviceType));
}

export const areDeviceTypesCompatible = async (
Expand Down

0 comments on commit 13edfe7

Please sign in to comment.