Skip to content

Commit

Permalink
πŸ› Make constructor task handling more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Oct 19, 2024
1 parent b8a04c0 commit 6fd9caf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.9.4 (WIP)

* Fix `RequestEvents` class restarting request that is already being handled
* Make constructor task handling more robust

## 0.9.3 (2024-08-12)

Expand Down
48 changes: 46 additions & 2 deletions lib/function_inheritance.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,56 @@ Blast.parseClassPath = function parseClassPath(path) {
return result;
};

/**
* Get the identifier of a constructor
*
* @author Jelle De Loecker <[email protected]>
* @since 0.9.4
* @version 0.9.4
*
* @param {Function} constructor
*
* @return {String}
*/
const getClassIdentifier = constructor => {
let result = constructor.name;

if (constructor.namespace) {
result = constructor.namespace + '.' + result;
}

return result;
};

/**
* Call a task for the given constructor/class
*
* @author Jelle De Loecker <[email protected]>
* @since 0.9.4
* @version 0.9.4
*
* @param {Function} constructor
* @param {Function} task
*/
const callTaskForConstructor = (constructor, task, ...args) => {
try {
return task.call(...args);
} catch (err) {

let new_error = new Error('Error in class "' + getClassIdentifier(constructor) + '": ' + err.message);
new_error.stack = err.stack;
new_error.original_error = err;

throw new_error;
}
}

/**
* Do the given task for a given constructor
*
* @author Jelle De Loecker <[email protected]>
* @since 0.3.6
* @version 0.9.0
* @version 0.9.4
*
* @param {Function} constructor
* @param {Function} task
Expand All @@ -442,7 +486,7 @@ const doConstructorTask = function doConstructorTask(constructor, task, finished
}

if (finished.indexOf(task) == -1) {
task.call(constructor);
callTaskForConstructor(constructor, task, constructor);
finished.push(task);
}
};
Expand Down

0 comments on commit 6fd9caf

Please sign in to comment.