@@ -45,7 +45,7 @@ class Result {
4545 * @param {ConnectionHolder } connectionHolder - to be notified when result is either fully consumed or error happened.
4646 */
4747 constructor ( streamObserver , statement , parameters , metaSupplier , connectionHolder ) {
48- this . _stack = ( new Error ( '' ) ) . stack . substr ( 6 ) ; // we don't need the 'Error\n' part
48+ this . _stack = captureStacktrace ( ) ;
4949 this . _streamObserver = streamObserver ;
5050 this . _p = null ;
5151 this . _statement = statement ;
@@ -138,9 +138,7 @@ class Result {
138138 // notify connection holder that the used connection is not needed any more because error happened
139139 // and result can't bee consumed any further; call the original onError callback after that
140140 self . _connectionHolder . releaseConnection ( ) . then ( ( ) => {
141- // Error.prototype.toString() concatenates error.name and error.message nicely
142- // then we add the rest of the stack trace
143- error . stack = error . toString ( ) + '\n' + this . _stack ;
141+ replaceStacktrace ( error , this . _stack ) ;
144142 onErrorOriginal . call ( observer , error ) ;
145143 } ) ;
146144 } ;
@@ -150,4 +148,20 @@ class Result {
150148 }
151149}
152150
153- export default Result
151+ function captureStacktrace ( ) {
152+ const error = new Error ( '' ) ;
153+ if ( error . stack ) {
154+ return error . stack . substr ( 6 ) ; // we don't need the 'Error\n' part
155+ }
156+ return null ;
157+ }
158+
159+ function replaceStacktrace ( error , newStack ) {
160+ if ( newStack ) {
161+ // Error.prototype.toString() concatenates error.name and error.message nicely
162+ // then we add the rest of the stack trace
163+ error . stack = error . toString ( ) + '\n' + newStack ;
164+ }
165+ }
166+
167+ export default Result ;
0 commit comments