« get me outta code hell

data: language: nicer language labelling for successive errors - 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-11-06 18:43:49 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-06 18:45:03 -0400
commit9f3a1f476752059681fbe21f8a1f7bf11dd73c9b (patch)
tree98174852de4e0f30c15a569372e179d70e6b153f /src
parent06949e1d20d38d38eb05999ca236f2c7d150691e (diff)
data: language: nicer language labelling for successive errors
Diffstat (limited to 'src')
-rw-r--r--src/data/language.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/data/language.js b/src/data/language.js
index 5ab3936e..99eaa58f 100644
--- a/src/data/language.js
+++ b/src/data/language.js
@@ -17,7 +17,7 @@ import {
 
 const {Language} = T;
 
-export function processLanguageSpec(spec) {
+export function processLanguageSpec(spec, {existingCode = null}) {
   const {
     'meta.languageCode': code,
     'meta.languageName': name,
@@ -36,12 +36,16 @@ export function processLanguageSpec(spec) {
     if (!name) {
       push(new Error(`Missing language name`));
     }
+
+    if (code && existingCode && code !== existingCode) {
+      push(new Error(`Language code (${code}) doesn't match previous value\n(You'll have to reload hsmusic to load this)`));
+    }
   });
 
   return {code, intlCode, name, hidden, strings};
 }
 
-async function processLanguageSpecFromFile(file) {
+async function processLanguageSpecFromFile(file, processLanguageSpecOpts) {
   let contents, spec;
 
   try {
@@ -61,7 +65,7 @@ async function processLanguageSpecFromFile(file) {
   }
 
   try {
-    return processLanguageSpec(spec);
+    return processLanguageSpec(spec, processLanguageSpecOpts);
   } catch (caughtError) {
     throw annotateErrorWithFile(caughtError, file);
   }
@@ -118,15 +122,25 @@ export function watchLanguageFile(file, {
     let properties;
 
     try {
-      properties = await processLanguageSpecFromFile(file);
+      properties = await processLanguageSpecFromFile(file, {
+        existingCode:
+          (successfullyAppliedLanguage
+            ? language.code
+            : null),
+      });
     } catch (error) {
       events.emit('error', error);
 
       if (logging) {
+        const label =
+          (successfullyAppliedLanguage
+            ? `${language.name} (${language.code})`
+            : basename);
+
         if (successfullyAppliedLanguage) {
-          logWarn`Failed to load language ${basename} - using existing version`;
+          logWarn`Failed to load language ${label} - using existing version`;
         } else {
-          logWarn`Failed to load language ${basename} - no prior version loaded`;
+          logWarn`Failed to load language ${label} - no prior version loaded`;
         }
         showAggregate(error, {showTraces: false});
       }