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 () {
121
121
122
122
it ( 'throws an error if internal methods are used too early' , function ( ) {
123
123
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 /
125
125
) ;
126
126
} ) ;
127
127
Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ type Mutable<T> = {
126
126
*/
127
127
class MongoshNodeRepl implements EvaluationListener {
128
128
_runtimeState : MongoshRuntimeState | null ;
129
+ closeTrace ?: string ;
129
130
input : Readable ;
130
131
lineByLineInput : LineByLineInput ;
131
132
output : Writable ;
@@ -1028,7 +1029,13 @@ class MongoshNodeRepl implements EvaluationListener {
1028
1029
*/
1029
1030
runtimeState ( ) : MongoshRuntimeState {
1030
1031
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
+ ) ;
1032
1039
}
1033
1040
return this . _runtimeState ;
1034
1041
}
@@ -1043,6 +1050,7 @@ class MongoshNodeRepl implements EvaluationListener {
1043
1050
const rs = this . _runtimeState ;
1044
1051
if ( rs ) {
1045
1052
this . _runtimeState = null ;
1053
+ this . closeTrace = new Error ( ) . stack ;
1046
1054
rs . repl ?. close ( ) ;
1047
1055
await rs . instanceState . close ( true ) ;
1048
1056
await new Promise ( ( resolve ) => this . output . write ( '' , resolve ) ) ;
You can’t perform that action at this time.
0 commit comments