diff options
Diffstat (limited to 'src/data/checks.js')
-rw-r--r-- | src/data/checks.js | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/data/checks.js b/src/data/checks.js index 44f3efd7..ad621bab 100644 --- a/src/data/checks.js +++ b/src/data/checks.js @@ -24,20 +24,30 @@ function inspect(value, opts = {}) { return nodeInspect(value, {colors: ENABLE_COLOR, ...opts}); } -// Warn about directories which are reused across more than one of the same type -// of Thing. Directories are the unique identifier for most data objects across -// the wiki, so we have to make sure they aren't duplicated! -export function reportDuplicateDirectories(wikiData, { +// Warn about problems to do with directories. +// +// * Duplicate directories: these are the unique identifier for referencable +// data objects across the wiki, so duplicates introduce ambiguity where it +// can't fit. +// +// * Missing directories: in almost all cases directories can be computed, +// but in particularly brutal internal cases, it might not be possible, and +// a thing's directory is just null. This leaves it unable to be referenced. +// +export function reportDirectoryErrors(wikiData, { getAllFindSpecs, }) { const duplicateSets = []; + const missingDirectoryThings = new Set(); for (const findSpec of Object.values(getAllFindSpecs())) { if (!findSpec.bindTo) continue; const directoryPlaces = Object.create(null); const duplicateDirectories = new Set(); + const thingData = wikiData[findSpec.bindTo]; + if (!thingData) continue; for (const thing of thingData) { if (findSpec.include && !findSpec.include(thing)) { @@ -50,6 +60,11 @@ export function reportDuplicateDirectories(wikiData, { : [thing.directory]); for (const directory of directories) { + if (directory === null || directory === undefined) { + missingDirectoryThings.add(thing); + continue; + } + if (directory in directoryPlaces) { directoryPlaces[directory].push(thing); duplicateDirectories.add(directory); @@ -59,8 +74,6 @@ export function reportDuplicateDirectories(wikiData, { } } - if (empty(duplicateDirectories)) continue; - const sortedDuplicateDirectories = Array.from(duplicateDirectories) .sort((a, b) => { @@ -75,8 +88,6 @@ export function reportDuplicateDirectories(wikiData, { } } - if (empty(duplicateSets)) return; - // Multiple find functions may effectively have duplicates across the same // things. These only need to be reported once, because resolving one of them // will resolve the rest, so cut out duplicate sets before reporting. @@ -84,6 +95,7 @@ export function reportDuplicateDirectories(wikiData, { const seenDuplicateSets = new Map(); const deduplicateDuplicateSets = []; + iterateSets: for (const set of duplicateSets) { if (seenDuplicateSets.has(set.directory)) { const placeLists = seenDuplicateSets.get(set.directory); @@ -95,7 +107,7 @@ export function reportDuplicateDirectories(wikiData, { // Two artists named Foodog aren't going to match two tracks named // Foodog. if (compareArrays(places, set.places, {checkOrder: false})) { - continue; + continue iterateSets; } } @@ -107,12 +119,20 @@ export function reportDuplicateDirectories(wikiData, { deduplicateDuplicateSets.push(set); } - withAggregate({message: `Duplicate directories found`}, ({push}) => { + withAggregate({message: `Directory errors detected`}, ({push}) => { for (const {directory, places} of deduplicateDuplicateSets) { push(new Error( `Duplicate directory ${colors.green(`"${directory}"`)}:\n` + places.map(thing => ` - ` + inspect(thing)).join('\n'))); } + + if (!empty(missingDirectoryThings)) { + push(new Error( + `Couldn't figure out an implicit directory for:\n` + + Array.from(missingDirectoryThings) + .map(thing => `- ` + inspect(thing)) + .join('\n'))); + } }); } @@ -261,7 +281,7 @@ export function filterReferenceErrors(wikiData, { break; case '_contrib': - findFn = contribRef => findArtistOrAlias(contribRef.who); + findFn = contribRef => findArtistOrAlias(contribRef.artist); break; case '_homepageSourceGroup': |