Skip to content

Commit

Permalink
Format error message when validating checklist metadata (#6023)
Browse files Browse the repository at this point in the history
* update ckl metadata validation error message

Signed-off-by: Kaden Emley <[email protected]>

* indent error message output for clarity

Signed-off-by: Kaden Emley <[email protected]>

* linting

Signed-off-by: Kaden Emley <[email protected]>

---------

Signed-off-by: Kaden Emley <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
kemley76 and mergify[bot] authored Jul 29, 2024
1 parent 0448daa commit 0d0a84f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions libs/hdf-converters/src/ckl-mapper/checklist-metadata-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function validateChecklistAssetMetadata(
const invalidFields = errors.map(
(e) => `${e.message} (${_.get(asset, e.property)})`
);
const message = `Invalid checklist metadata fields: ${invalidFields.join(', ')}`;
const message = `Invalid checklist metadata fields:\n\t${invalidFields.join('\n\t')}`;
return {ok: false, error: {invalid: errors.map((e) => e.property), message}};
}

Expand All @@ -93,7 +93,7 @@ export function validateChecklistProfileMetadata(
const invalidFields = errors.map(
(e) => `${e.message} (${_.get(metadata, e.property)})`
);
const message = `Invalid checklist profile metadata fields: ${invalidFields.join(', ')}`;
const message = `Invalid checklist profile metadata fields:\n\t${invalidFields.join('\n\t')}`;
return {ok: false, error: {invalid: errors.map((e) => e.property), message}};
}

Expand All @@ -104,7 +104,7 @@ export function validateChecklistMetadata(
const messages: string[] = [];
const assetResult = validateChecklistAssetMetadata({
...metadata,
webordatabase: metadata.webdbinstance === 'true',
webordatabase: metadata.webordatabase === 'true',
targetkey: null
});
if (!assetResult.ok) {
Expand All @@ -116,13 +116,15 @@ export function validateChecklistMetadata(
const profileResult = validateChecklistProfileMetadata(profile);
if (!profileResult.ok) {
invalid = invalid.concat(profileResult.error.invalid);
messages.push(`Profile ${profile.name}: ${profileResult.error.message}`);
messages.push(
`In profile ${profile.name}:\n${profileResult.error.message.split(':\n').at(-1)}`
);
}
}

if (invalid.length === 0) return {ok: true, value: true};

const message = messages.join(', ');
const message = messages.join('\n');
return {ok: false, error: {invalid, message}};
}

Expand Down

0 comments on commit 0d0a84f

Please sign in to comment.