@@ -45,7 +45,7 @@ class Result {
45
45
* @param {ConnectionHolder } connectionHolder - to be notified when result is either fully consumed or error happened.
46
46
*/
47
47
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 ( ) ;
49
49
this . _streamObserver = streamObserver ;
50
50
this . _p = null ;
51
51
this . _statement = statement ;
@@ -138,9 +138,7 @@ class Result {
138
138
// notify connection holder that the used connection is not needed any more because error happened
139
139
// and result can't bee consumed any further; call the original onError callback after that
140
140
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 ) ;
144
142
onErrorOriginal . call ( observer , error ) ;
145
143
} ) ;
146
144
} ;
@@ -150,4 +148,20 @@ class Result {
150
148
}
151
149
}
152
150
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