-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Make constructor task handling more robust
- Loading branch information
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
}; | ||
|