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 committed Nov 8, 2022
1 parent 535ffcc commit 3bb1577
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,21 @@ 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) {
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 (
Expand Down

0 comments on commit 3bb1577

Please sign in to comment.