Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
fix: handle empty files
Browse files Browse the repository at this point in the history
* Add placeholders for alerts
* Add multi-doc parsing for alerts, but only take first
* Add placeholders and JSON parse try/catch for dashboards
  • Loading branch information
aswanson-nr committed May 23, 2022
1 parent 56c3ea6 commit 9b52723
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/utils/preview/parseHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ export const parseDashboardFiles = (files) => {
dashFileMetadata.fileName
)[0];

const { name = '', description = '' } = JSON.parse(
dashFileMetadata.content
);
let dashboard = {};
try {
dashboard = JSON.parse(dashFileMetadata.content);
} catch (err) {
console.error(err);
}

return {
name,
description,
name: dashboard?.name ?? 'Placeholder name',
description: dashboard?.description ?? 'Placeholder description',
screenshots: screenshots
.filter((s) => s.filePath.includes(parentDir))
.map(({ content }) => content),
Expand All @@ -114,13 +117,13 @@ export const parseDashboardFiles = (files) => {
*/
export const parseAlertFiles = (alertFiles) => {
return alertFiles.map((file) => {
const loadYaml = yaml.load(file.content);
const loadYaml = yaml.loadAll(file.content)[0];

//parse and build alert object and add it to the array
return {
details: loadYaml.description?.trim() ?? '',
name: loadYaml.name?.trim() ?? '',
type: loadYaml.type?.trim() ?? '',
details: loadYaml?.description?.trim() ?? 'Placeholder description',
name: loadYaml?.name?.trim() ?? 'Placeholder name',
type: loadYaml?.type?.trim() ?? 'Placeholder type',
};
});
};
Expand Down

0 comments on commit 9b52723

Please sign in to comment.