« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things/cacheable-object.js19
-rw-r--r--src/data/things/index.js6
2 files changed, 17 insertions, 8 deletions
diff --git a/src/data/things/cacheable-object.js b/src/data/things/cacheable-object.js
index 4bc3668d..9fda865e 100644
--- a/src/data/things/cacheable-object.js
+++ b/src/data/things/cacheable-object.js
@@ -179,13 +179,8 @@ export default class CacheableObject {
           } else if (result !== true) {
             throw new TypeError(`Validation failed for value ${newValue}`);
           }
-        } catch (error) {
-          error.message = [
-            `Property ${colors.green(property)}`,
-            `(${inspect(this[property])} -> ${inspect(newValue)}):`,
-            error.message
-          ].join(' ');
-          throw error;
+        } catch (caughtError) {
+          throw new CacheableObjectPropertyValueError(property, this[property], newValue, caughtError);
         }
       }
 
@@ -359,3 +354,13 @@ export default class CacheableObject {
     return object.#propertyUpdateValues[key] ?? null;
   }
 }
+
+export class CacheableObjectPropertyValueError extends Error {
+  constructor(property, oldValue, newValue, error) {
+    super(
+      `Error setting ${colors.green(property)} (${inspect(oldValue)} -> ${inspect(newValue)})`,
+      {cause: error});
+
+    this.property = property;
+  }
+}
diff --git a/src/data/things/index.js b/src/data/things/index.js
index 77e5fa76..4ea1f007 100644
--- a/src/data/things/index.js
+++ b/src/data/things/index.js
@@ -21,7 +21,11 @@ import * as trackClasses from './track.js';
 import * as wikiInfoClasses from './wiki-info.js';
 
 export {default as Thing} from './thing.js';
-export {default as CacheableObject} from './cacheable-object.js';
+
+export {
+  default as CacheableObject,
+  CacheableObjectPropertyValueError,
+} from './cacheable-object.js';
 
 const allClassLists = {
   'album.js': albumClasses,