Skip to content

Commit

Permalink
Merge pull request #1553 from DaoDaoNoCode/upstream-issue-1493
Browse files Browse the repository at this point in the history
Gracefully handle image packages and software JSON parse error
  • Loading branch information
openshift-merge-robot authored Aug 1, 2023
2 parents 2baee3e + 8daf822 commit f693c03
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions backend/src/routes/api/images/imageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ const getTagInfo = (imageStream: ImageStream): ImageTagInfo[] => {

const getTagContent = (tag: ImageStreamTag): TagContent => {
const content: TagContent = {
software: JSON.parse(tag.annotations[IMAGE_ANNOTATIONS.SOFTWARE] || '[]'),
dependencies: JSON.parse(tag.annotations[IMAGE_ANNOTATIONS.DEPENDENCIES] || '[]'),
software: jsonParsePackage(tag.annotations[IMAGE_ANNOTATIONS.SOFTWARE]),
dependencies: jsonParsePackage(tag.annotations[IMAGE_ANNOTATIONS.DEPENDENCIES]),
};
return content;
};
Expand All @@ -194,16 +194,10 @@ const mapImageStreamToBYONImage = (is: ImageStream): BYONImage => ({
description: is.metadata.annotations['opendatahub.io/notebook-image-desc'],
visible: is.metadata.labels['opendatahub.io/notebook-image'] === 'true',
error: getBYONImageErrorMessage(is),
packages:
is.spec.tags &&
(JSON.parse(
is.spec.tags[0].annotations['opendatahub.io/notebook-python-dependencies'],
) as BYONImagePackage[]),
software:
is.spec.tags &&
(JSON.parse(
is.spec.tags[0].annotations['opendatahub.io/notebook-software'],
) as BYONImagePackage[]),
packages: jsonParsePackage(
is.spec.tags?.[0]?.annotations?.['opendatahub.io/notebook-python-dependencies'],
),
software: jsonParsePackage(is.spec.tags?.[0]?.annotations?.['opendatahub.io/notebook-software']),
uploaded: is.metadata.creationTimestamp,
url: is.metadata.annotations['opendatahub.io/notebook-image-url'],
user: is.metadata.annotations['opendatahub.io/notebook-image-creator'],
Expand Down Expand Up @@ -408,3 +402,11 @@ export const updateImage = async (
}
}
};

const jsonParsePackage = (unparsedPackage: string): BYONImagePackage[] => {
try {
return JSON.parse(unparsedPackage) || [];
} catch {
return [];
}
};

0 comments on commit f693c03

Please sign in to comment.