« get me outta code hell

yaml: error when combining Cover Artists, Has Cover Art - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-18 14:38:06 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-18 14:38:06 -0300
commite3d38e8c66e44f47df36ff00e4448386c085f6bb (patch)
tree516261b6fc8117d96820196ce5d1124da4ce08ca /src/data
parent8044dc9eb058761038e0ad81aa6e6378a8b9cbd4 (diff)
yaml: error when combining Cover Artists, Has Cover Art
Diffstat (limited to 'src/data')
-rw-r--r--src/data/yaml.js32
1 files changed, 28 insertions, 4 deletions
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',
+      ],
+    },
   ],
 });