Skip to content

Commit

Permalink
feat: show purl error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoKorinth committed Nov 26, 2024
1 parent b5a6809 commit 58b4391
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/mandatoryTests/mandatoryTest_6_1_13.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function mandatoryTest_6_1_13(doc) {
/** @type {any} */ fullProductName,
/** @type {number} */ fullProductNameIndex
) => {
checkProductIdentificationHelperPURL(fullProductName, () => {
checkProductIdentificationHelperPURL(fullProductName, (errorMessage) => {
isValid = false
errors.push({
instancePath: `/product_tree/full_product_names/${fullProductNameIndex}/product_identification_helper/purl`,
message: `invalid purl`,
message: `invalid purl: ${errorMessage}`,
})
})
}
Expand All @@ -35,11 +35,11 @@ export default function mandatoryTest_6_1_13(doc) {
) => {
checkProductIdentificationHelperPURL(
relationship.full_product_name,
() => {
(errorMessage) => {
isValid = false
errors.push({
instancePath: `/product_tree/relationships/${relationshipIndex}/full_product_name/product_identification_helper/purl`,
message: `invalid purl`,
message: `invalid purl: ${errorMessage}`,
})
}
)
Expand All @@ -48,15 +48,15 @@ export default function mandatoryTest_6_1_13(doc) {
}

if (doc.product_tree) {
checkBranchesForInvalidPURLs(doc.product_tree, ({ branchIndexes }) => {
checkBranchesForInvalidPURLs(doc.product_tree, ({ branchIndexes, errorMessage }) => {
isValid = false
const branchPathPart = branchIndexes.reduce(
(str, index) => `${str}/branches/${index}`,
'/product_tree'
)
errors.push({
instancePath: `${branchPathPart}/product/product_identification_helper/purl`,
message: `invalid purl`,
message: `invalid purl: ${errorMessage}`,
})
})
}
Expand All @@ -67,7 +67,7 @@ export default function mandatoryTest_6_1_13(doc) {
/**
*
* @param {any} parent
* @param {(error: { branchIndexes: number[] }) => void} onError
* @param {(error: { branchIndexes: number[], errorMessage: string }) => void} onError
* @param {number[]} [branchIndexes]
*/
const checkBranchesForInvalidPURLs = (parent, onError, branchIndexes = []) => {
Expand All @@ -76,9 +76,10 @@ const checkBranchesForInvalidPURLs = (parent, onError, branchIndexes = []) => {
(/** @type {any} */ branch, /** @type {number} */ branchIndex) => {
const currentBranchIndexes = branchIndexes.concat([branchIndex])

checkProductIdentificationHelperPURL(branch.product, () => {
checkProductIdentificationHelperPURL(branch.product, (errorMessage) => {
onError({
branchIndexes: currentBranchIndexes,
errorMessage,
})
})
checkBranchesForInvalidPURLs(branch, onError, currentBranchIndexes)
Expand All @@ -89,7 +90,7 @@ const checkBranchesForInvalidPURLs = (parent, onError, branchIndexes = []) => {

/**
* @param {any} productALike
* @param {() => void} onError
* @param {(errorMessage: string) => void} onError
* @returns
*/
const checkProductIdentificationHelperPURL = (productALike, onError) => {
Expand All @@ -98,6 +99,7 @@ const checkProductIdentificationHelperPURL = (productALike, onError) => {
try {
PackageURL.fromString(productALike?.product_identification_helper?.purl)
} catch (e) {
onError()
const errorObject = /** @type {{message: string}} */ (e)
onError(errorObject?.message ?? "Unknown purl error")
}
}

0 comments on commit 58b4391

Please sign in to comment.