I noticed in my app that the stack traces for instances of CheckitError indicate where the error function was defined, rather than where it is raised. I tracked this down to CheckitError.prototype.stack being set via CheckitError.prototype = new Error.
To fix, I added some logic to abstract the process of creating a custom error type, and to calculate the stack trace when created, using Error.captureStackTrace if available, or via a cleaned version of new Error(msg).stack otherwise.
I noticed in my app that the stack traces for instances of
CheckitError
indicate where the error function was defined, rather than where it is raised. I tracked this down toCheckitError.prototype.stack
being set viaCheckitError.prototype = new Error
.To fix, I added some logic to abstract the process of creating a custom error type, and to calculate the stack trace when created, using
Error.captureStackTrace
if available, or via a cleaned version ofnew Error(msg).stack
otherwise.