« get me outta code hell

find: fix error reporting for multiple name matches - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-10-10 07:59:49 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-10-10 07:59:49 -0300
commitcc4c12ad31be6b6d8432f257e112195179f7eafa (patch)
tree5d573ecff48cc0e481ede5ebdd7bcdb18cf5b923 /src
parent822d0ad890cbdb2a780a2fdf7d1c1aa053fc1d77 (diff)
find: fix error reporting for multiple name matches
Diffstat (limited to 'src')
-rw-r--r--src/find.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/find.js b/src/find.js
index c8edce98..5a249c28 100644
--- a/src/find.js
+++ b/src/find.js
@@ -34,11 +34,12 @@ export function processAllAvailableMatches(data, {
 
       const normalizedName = name.toLowerCase();
       if (normalizedName in byName) {
+        const alreadyMatchesByName = byName[normalizedName];
         byName[normalizedName] = null;
         if (normalizedName in multipleNameMatches) {
           multipleNameMatches[normalizedName].push(thing);
         } else {
-          multipleNameMatches[normalizedName] = [thing];
+          multipleNameMatches[normalizedName] = [alreadyMatchesByName, thing];
         }
       } else {
         byName[normalizedName] = thing;
@@ -97,16 +98,21 @@ function findHelper({
     const typePart = regexMatch[1];
     const refPart = regexMatch[2];
 
+    const normalizedName =
+      (typePart
+        ? null
+        : refPart.toLowerCase());
+
     const match =
       (typePart
         ? subcache.byDirectory[refPart]
-        : subcache.byName[refPart.toLowerCase()]);
+        : subcache.byName[normalizedName]);
 
     if (!match && !typePart) {
-      if (subcache.multipleNameMatches[refPart]) {
+      if (subcache.multipleNameMatches[normalizedName]) {
         return warnOrThrow(mode,
           `Multiple matches for reference "${fullRef}". Please resolve:\n` +
-          subcache.multipleNameMatches[refPart]
+          subcache.multipleNameMatches[normalizedName]
             .map(match => `- ${inspect(match)}\n`)
             .join('') +
           `Returning null for this reference.`);