Skip to content

OnPrem: Get compose status could exit early and ignore compose status (HMS-10350) #4200

@kingsleyzissou

Description

@kingsleyzissou

The following lines could potentially cause an error that throws an error causing the loop to break and only one item being read
if the file is not found or if the file somehow gets corrupt. This means the loop will exit early and we might not get all the compose statuses we're looking for.

const request = await cockpit
.file(path.join(blueprintsDir, bpEntry[0], queryArg.composeId))
.read();

Expected Behavior

The loop should continue searching other blueprint directories if the compose file
isn't found in the current one.

Suggested Fix

Wrap the file read in a try-catch and continue the loop on error.

for (const bpEntry of entries) {
  try {
    const request = await cockpit
      .file(path.join(blueprintsDir, bpEntry[0], queryArg.composeId))
      .read();
    return {
      data: {
        image_status: data.image_status,
        request: JSON.parse(request),
      },
    };
  } catch {
    // File not found in this blueprint directory, continue searching
    continue;
  }
}

JIRA: HMS-10350

Metadata

Metadata

Assignees

No one assigned

    Labels

    cockpit-image-builderCan be reproduces in image builder plugin in Cockpit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions