Skip to content

Commit

Permalink
chore: rework variables to avoid potential undefined values
Browse files Browse the repository at this point in the history
avoid to have wantedOses.keys().next().value that can be undefined

related to #8814
Signed-off-by: Florent Benoit <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Sep 20, 2024
1 parent c1cf931 commit d210129
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/main/src/plugin/image-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ export class ImageRegistry {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
getBestManifest(manifests: any[], wantedArch: string, wantedOs: string): any {
getBestManifest(manifests: any[], wantedArch: string, wantedOs: string): any | undefined {
// eslint-disable-next-line etc/no-commented-out-code
// manifestsMap [os] [arch] = manifest
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -739,14 +739,16 @@ export class ImageRegistry {
if (!wantedOses) {
wantedOses = manifestsMap.get('linux');
}
if (!wantedOses) {

const keys = Array.from(wantedOses?.keys() ?? []);
if (!wantedOses || !keys[0]) {
return;
}

let wanted = wantedOses.get(wantedArch);
if (!wanted) {
if (wantedOses.size === 1) {
wanted = wantedOses.get(wantedOses.keys().next().value);
wanted = wantedOses.get(keys[0]);
} else {
wanted = wantedOses.get('amd64');
}
Expand Down

0 comments on commit d210129

Please sign in to comment.