From 24fc9a842159c16a2d4bb3dc01c5640218caff06 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 2 Oct 2023 11:03:28 -0300 Subject: find: use more reasonable getMatchableNames default Also warn with some details when getMatchableNames returns values besides strings. This was getting caught on links to listings, which don't have (data-represented) names. --- src/find.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/find.js b/src/find.js index 78775457..c8edce98 100644 --- a/src/find.js +++ b/src/find.js @@ -16,7 +16,10 @@ function warnOrThrow(mode, message) { } export function processAllAvailableMatches(data, { - getMatchableNames = thing => [thing.name], + getMatchableNames = thing => + (Object.hasOwn(thing, 'name') + ? [thing.name] + : []), } = {}) { const byName = Object.create(null); const byDirectory = Object.create(null); @@ -24,6 +27,11 @@ export function processAllAvailableMatches(data, { for (const thing of data) { for (const name of getMatchableNames(thing)) { + if (typeof name !== 'string') { + logWarn`Unexpected ${typeAppearance(name)} returned in names for ${inspect(thing)}`; + continue; + } + const normalizedName = name.toLowerCase(); if (normalizedName in byName) { byName[normalizedName] = null; -- cgit 1.3.0-6-gf8a5