File tree 4 files changed +53
-3
lines changed
4 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 12
12
13
13
## master
14
14
15
+ - Better error recovery when analysis fails. https://github.com/rescript-lang/rescript-vscode/pull/880
16
+
15
17
## 1.32.0
16
18
17
19
- Expand type aliases in hovers. https://github.com/rescript-lang/rescript-vscode/pull/881
Original file line number Diff line number Diff line change
1
+ type cb = ( msg : string ) => void ;
2
+
3
+ let subscribers : Array < cb > = [ ] ;
4
+ const errorLastNotified : Record < string , number > = { } ;
5
+
6
+ export const onErrorReported = ( cb : ( msg : string ) => void ) => {
7
+ subscribers . push ( cb ) ;
8
+ return ( ) => {
9
+ subscribers = subscribers . filter ( ( s ) => s !== cb ) ;
10
+ } ;
11
+ } ;
12
+
13
+ export const reportError = ( identifier : string , msg : string ) => {
14
+ // Warn once per 15 min per error
15
+ if (
16
+ errorLastNotified [ identifier ] == null ||
17
+ errorLastNotified [ identifier ] < Date . now ( ) - 15 * 1000 * 60
18
+ ) {
19
+ errorLastNotified [ identifier ] = Date . now ( ) ;
20
+ subscribers . forEach ( ( cb ) => cb ( msg ) ) ;
21
+ }
22
+ } ;
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import { fileURLToPath } from "url";
25
25
import { ChildProcess } from "child_process" ;
26
26
import { WorkspaceEdit } from "vscode-languageserver" ;
27
27
import { filesDiagnostics } from "./utils" ;
28
+ import { onErrorReported } from "./errorReporter" ;
28
29
29
30
interface extensionConfiguration {
30
31
allowBuiltInFormatter : boolean ;
@@ -1306,3 +1307,21 @@ function onMessage(msg: p.Message) {
1306
1307
}
1307
1308
}
1308
1309
}
1310
+
1311
+ // Gate behind a debug setting potentially?
1312
+ onErrorReported ( ( msg ) => {
1313
+ let params : p . ShowMessageParams = {
1314
+ type : p . MessageType . Warning ,
1315
+ message : `ReScript tooling: Internal error. Something broke. Here's the error message that you can report if you want:
1316
+
1317
+ ${ msg }
1318
+
1319
+ (this message will only be reported once every 15 minutes)` ,
1320
+ } ;
1321
+ let message : p . NotificationMessage = {
1322
+ jsonrpc : c . jsonrpcVersion ,
1323
+ method : "window/showMessage" ,
1324
+ params : params ,
1325
+ } ;
1326
+ send ( message ) ;
1327
+ } ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import * as os from "os";
12
12
import * as codeActions from "./codeActions" ;
13
13
import * as c from "./constants" ;
14
14
import * as lookup from "./lookup" ;
15
+ import { reportError } from "./errorReporter" ;
15
16
16
17
let tempFilePrefix = "rescript_format_file_" + process . pid + "_" ;
17
18
let tempFileId = 0 ;
@@ -186,9 +187,15 @@ export let runAnalysisAfterSanityCheck = (
186
187
RESCRIPT_VERSION : rescriptVersion ,
187
188
} ,
188
189
} ;
189
- let stdout = childProcess . execFileSync ( binaryPath , args , options ) ;
190
-
191
- return JSON . parse ( stdout . toString ( ) ) ;
190
+ try {
191
+ let stdout = childProcess . execFileSync ( binaryPath , args , options ) ;
192
+ return JSON . parse ( stdout . toString ( ) ) ;
193
+ } catch ( e ) {
194
+ console . error ( e ) ;
195
+ // Element 0 is the action we're performing
196
+ reportError ( String ( args [ 0 ] ) , String ( e ) ) ;
197
+ return null ;
198
+ }
192
199
} ;
193
200
194
201
export let runAnalysisCommand = (
You can’t perform that action at this time.
0 commit comments