Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle image packages and software JSON parse error #1553

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [];
}
};
Loading