« get me outta code hell

data, yaml: match Error constructors more closely when extending - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-06 09:23:14 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-06 09:23:14 -0400
commit39c553661b354a7cddc8de80315dd99337f1dde2 (patch)
tree1be32284acd4ee4cbeea64702da78a4a18149c0b
parentbca7dbeebc6205aa36d480d9dd9db9c645c7b353 (diff)
data, yaml: match Error constructors more closely when extending
-rw-r--r--src/data/things/cacheable-object.js4
-rw-r--r--src/data/yaml.js12
2 files changed, 9 insertions, 7 deletions
diff --git a/src/data/things/cacheable-object.js b/src/data/things/cacheable-object.js
index 6b8d5def..c6f154c0 100644
--- a/src/data/things/cacheable-object.js
+++ b/src/data/things/cacheable-object.js
@@ -358,10 +358,10 @@ export default class CacheableObject {
 export class CacheableObjectPropertyValueError extends Error {
   [Symbol.for('hsmusic.aggregate.translucent')] = true;
 
-  constructor(property, oldValue, newValue, error) {
+  constructor(property, oldValue, newValue, options) {
     super(
       `Error setting ${colors.green(property)} (${inspect(oldValue)} -> ${inspect(newValue)})`,
-      {cause: error});
+      options);
 
     this.property = property;
   }
diff --git a/src/data/yaml.js b/src/data/yaml.js
index caf414e5..72e212b9 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -262,12 +262,14 @@ function makeProcessDocument(
         thing[property] = value;
       } catch (caughtError) {
         skippedFields.add(field);
-        fieldValueErrors.push(new FieldValueError(field, value, caughtError));
+        fieldValueErrors.push(new FieldValueError(
+          field, value, {cause: caughtError}));
       }
     }
 
     if (!empty(fieldValueErrors)) {
-      aggregate.push(new FieldValueAggregateError(thingConstructor, fieldValueErrors));
+      aggregate.push(new FieldValueAggregateError(
+        fieldValueErrors, thingConstructor));
     }
 
     if (skippedFields.size >= 1) {
@@ -335,7 +337,7 @@ export class FieldCombinationError extends Error {
 export class FieldValueAggregateError extends AggregateError {
   [Symbol.for('hsmusic.aggregate.translucent')] = true;
 
-  constructor(thingConstructor, errors) {
+  constructor(errors, thingConstructor) {
     const constructorText =
       colors.green(thingConstructor.name);
 
@@ -346,7 +348,7 @@ export class FieldValueAggregateError extends AggregateError {
 }
 
 export class FieldValueError extends Error {
-  constructor(field, value, cause) {
+  constructor(field, value, options) {
     const fieldText =
       colors.green(`"${field}"`);
 
@@ -355,7 +357,7 @@ export class FieldValueError extends Error {
 
     super(
       `Failed to set ${fieldText} field to ${valueText}`,
-      {cause});
+      options);
   }
 }