@@ -79,6 +79,14 @@ interface AutocompleteResultsMap {
79
79
[ i : number ] : CompletionItem ;
80
80
}
81
81
82
+ function formatUnknownError ( error : unknown ) {
83
+ let message : string | undefined ;
84
+ if ( error instanceof Error ) {
85
+ message = error . stack ;
86
+ }
87
+ return message ?? String ( error ) ;
88
+ }
89
+
82
90
function _getAutocompleteSuggestions (
83
91
queryText : string ,
84
92
point : Position ,
@@ -104,7 +112,7 @@ function _getAutocompleteSuggestions(
104
112
process . stdout . write ( JSON . stringify ( resultObject , null , 2 ) ) ;
105
113
return GRAPHQL_SUCCESS_CODE ;
106
114
} catch ( error ) {
107
- process . stderr . write ( ( error ?. stack ?? String ( error ) ) + '\n' ) ;
115
+ process . stderr . write ( formatUnknownError ( error ) + '\n' ) ;
108
116
return GRAPHQL_FAILURE_CODE ;
109
117
}
110
118
}
@@ -133,7 +141,7 @@ function _getDiagnostics(
133
141
process . stdout . write ( JSON . stringify ( resultObject , null , 2 ) ) ;
134
142
return GRAPHQL_SUCCESS_CODE ;
135
143
} catch ( error ) {
136
- process . stderr . write ( ( error ?. stack ?? String ( error ) ) + '\n' ) ;
144
+ process . stderr . write ( formatUnknownError ( error ) + '\n' ) ;
137
145
return GRAPHQL_FAILURE_CODE ;
138
146
}
139
147
}
@@ -147,7 +155,7 @@ function _getOutline(queryText: string): EXIT_CODE {
147
155
throw Error ( 'Error parsing or no outline tree found' ) ;
148
156
}
149
157
} catch ( error ) {
150
- process . stderr . write ( ( error ?. stack ?? String ( error ) ) + '\n' ) ;
158
+ process . stderr . write ( formatUnknownError ( error ) + '\n' ) ;
151
159
return GRAPHQL_FAILURE_CODE ;
152
160
}
153
161
return GRAPHQL_SUCCESS_CODE ;
@@ -161,7 +169,7 @@ function ensureText(queryText: string, filePath: string): string {
161
169
try {
162
170
text = fs . readFileSync ( filePath , 'utf8' ) ;
163
171
} catch ( error ) {
164
- throw new Error ( error ) ;
172
+ throw new Error ( String ( error ) ) ;
165
173
}
166
174
}
167
175
return text ;
0 commit comments