File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ describe('MongoshNodeRepl', function () {
121121
122122 it ( 'throws an error if internal methods are used too early' , function ( ) {
123123 expect ( ( ) => mongoshRepl . runtimeState ( ) ) . to . throw (
124- 'Mongosh not initialized yet'
124+ / m o n g o s h n o t i n i t i a l i z e d y e t \n C u r r e n t t r a c e /
125125 ) ;
126126 } ) ;
127127
Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ type Mutable<T> = {
126126 */
127127class MongoshNodeRepl implements EvaluationListener {
128128 _runtimeState : MongoshRuntimeState | null ;
129+ closeTrace ?: string ;
129130 input : Readable ;
130131 lineByLineInput : LineByLineInput ;
131132 output : Writable ;
@@ -1028,7 +1029,13 @@ class MongoshNodeRepl implements EvaluationListener {
10281029 */
10291030 runtimeState ( ) : MongoshRuntimeState {
10301031 if ( this . _runtimeState === null ) {
1031- throw new MongoshInternalError ( 'Mongosh not initialized yet' ) ;
1032+ // This error can be really hard to debug, so we always attach stack traces
1033+ // from both when .close() was called and when
1034+ throw new MongoshInternalError (
1035+ `mongosh not initialized yet\nCurrent trace: ${
1036+ new Error ( ) . stack
1037+ } \nClose trace: ${ this . closeTrace } \n`
1038+ ) ;
10321039 }
10331040 return this . _runtimeState ;
10341041 }
@@ -1043,6 +1050,7 @@ class MongoshNodeRepl implements EvaluationListener {
10431050 const rs = this . _runtimeState ;
10441051 if ( rs ) {
10451052 this . _runtimeState = null ;
1053+ this . closeTrace = new Error ( ) . stack ;
10461054 rs . repl ?. close ( ) ;
10471055 await rs . instanceState . close ( true ) ;
10481056 await new Promise ( ( resolve ) => this . output . write ( '' , resolve ) ) ;
You can’t perform that action at this time.
0 commit comments