From e3d38e8c66e44f47df36ff00e4448386c085f6bb Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 18 Aug 2023 14:38:06 -0300 Subject: yaml: error when combining Cover Artists, Has Cover Art --- src/data/yaml.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/data/yaml.js b/src/data/yaml.js index 7420ee4a..9ebce642 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -15,6 +15,7 @@ import { conditionallySuppressError, decorateErrorWithIndex, empty, + filterProperties, mapAggregate, openAggregate, showAggregate, @@ -159,12 +160,20 @@ function makeProcessDocument( const presentFields = Object.keys(document); const fieldCombinationErrors = []; + for (const {message, fields} of invalidFieldCombinations) { const fieldsPresent = presentFields.filter(field => fields.includes(field)); - if (fieldsPresent.length > 1) { - fieldCombinationErrors.push(new makeProcessDocument.FieldCombinationError(fieldsPresent, message)); + + if (fieldsPresent.length <= 1) { + continue; } + + fieldCombinationErrors.push( + new makeProcessDocument.FieldCombinationError( + filterProperties(document, fieldsPresent), + message)); } + if (!empty(fieldCombinationErrors)) { throw new makeProcessDocument.FieldCombinationsError(fieldCombinationErrors); } @@ -220,10 +229,13 @@ makeProcessDocument.FieldCombinationsError = class FieldCombinationsError extend makeProcessDocument.FieldCombinationError = class FieldCombinationError extends Error { constructor(fields, message) { - const combinePart = `Don't combine ${fields.map(field => color.red(field)).join(', ')}`; + const fieldNames = Object.keys(fields); + const combinePart = `Don't combine ${fieldNames.map(field => color.red(field)).join(', ')}`; const messagePart = - (message + (typeof message === 'function' + ? `: ${message(fields)}` + : typeof message === 'string' ? `: ${message}` : ``); @@ -363,6 +375,18 @@ export const processTrackDocument = makeProcessDocument(T.Track, { 'Originally Released As', 'Contributors', ]}, + + { + message: ({'Has Cover Art': hasCoverArt}) => + (hasCoverArt + ? `"Has Cover Art: true" is inferred from cover artist credits` + : `Tracks without cover art must not have cover artist credits`), + + fields: [ + 'Has Cover Art', + 'Cover Artists', + ], + }, ], }); -- cgit 1.3.0-6-gf8a5