diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-10-02 11:03:28 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-10-02 11:03:28 -0300 |
commit | 24fc9a842159c16a2d4bb3dc01c5640218caff06 (patch) | |
tree | 80b6aa7ca5119a2e134a00db24cc14283b475dd4 | |
parent | 44e47fb3316c5452d277166215bc7522b404047f (diff) |
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.
-rw-r--r-- | src/find.js | 10 |
1 files changed, 9 insertions, 1 deletions
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; |