fix: add a better handling in case only worker crashes (CR comments)

This commit is contained in:
Mariana Alanis 2022-06-14 11:59:39 -05:00 committed by Leonardo de Moura
parent b0f9754e0f
commit 4d7d82af86
4 changed files with 12 additions and 9 deletions

View file

@ -37,6 +37,7 @@ inductive ErrorCode where
| invalidRequest
| methodNotFound
| invalidParams
| internalError
| workerCrashed
| stackOverflow
| serverNotInitialized
@ -53,13 +54,14 @@ instance : FromJson ErrorCode := ⟨fun
| num (-32600 : Int) => return ErrorCode.invalidRequest
| num (-32601 : Int) => return ErrorCode.methodNotFound
| num (-32602 : Int) => return ErrorCode.invalidParams
| num (-32603 : Int) => return ErrorCode.workerCrashed
| num (-32604 : Int) => return ErrorCode.stackOverflow
| num (-32603 : Int) => return ErrorCode.internalError
| num (-32002 : Int) => return ErrorCode.serverNotInitialized
| num (-32001 : Int) => return ErrorCode.unknownErrorCode
| num (-32801 : Int) => return ErrorCode.contentModified
| num (-32800 : Int) => return ErrorCode.requestCancelled
| num (-32900 : Int) => return ErrorCode.rpcNeedsReconnect
| num (-32901 : Int) => return ErrorCode.workerCrashed
| num (-32902 : Int) => return ErrorCode.stackOverflow
| _ => throw "expected error code"⟩
instance : ToJson ErrorCode := ⟨fun
@ -67,13 +69,14 @@ instance : ToJson ErrorCode := ⟨fun
| ErrorCode.invalidRequest => (-32600 : Int)
| ErrorCode.methodNotFound => (-32601 : Int)
| ErrorCode.invalidParams => (-32602 : Int)
| ErrorCode.workerCrashed => (-32603 : Int)
| ErrorCode.stackOverflow => (-32604 : Int)
| ErrorCode.internalError => (-32603 : Int)
| ErrorCode.serverNotInitialized => (-32002 : Int)
| ErrorCode.unknownErrorCode => (-32001 : Int)
| ErrorCode.contentModified => (-32801 : Int)
| ErrorCode.requestCancelled => (-32800 : Int)
| ErrorCode.rpcNeedsReconnect => (-32900 : Int)⟩
| ErrorCode.rpcNeedsReconnect => (-32900 : Int)
| ErrorCode.workerCrashed => (-32901 : Int)
| ErrorCode.stackOverflow => (-32902 : Int)⟩
/- Uses separate constructors for notifications and errors because client and server
behavior is expected to be wildly different for both. -/

View file

@ -401,7 +401,7 @@ section MessageHandling
catch e =>
ctx.hOut.writeLspResponseError
{ id
code := ErrorCode.workerCrashed
code := ErrorCode.internalError
message := toString e }
return

View file

@ -42,7 +42,7 @@ private unsafe def handleRpcCallUnsafe (p : Lsp.RpcCallParams) : RequestM (Reque
match proc with
| Except.ok x => x.wrapper p.sessionId p.params
| Except.error e => throwThe RequestError {
code := JsonRpc.ErrorCode.workerCrashed
code := JsonRpc.ErrorCode.internalError
message := s!"Failed to evaluate RPC constant '{procName}': {e}" }
else
throwThe RequestError {

View file

@ -259,7 +259,7 @@ section ServerM
else
-- Worker crashed
fw.errorPendingRequests o (if exitCode = 1 then ErrorCode.workerCrashed else ErrorCode.stackOverflow)
s!"Server process for {fw.doc.meta.uri} crashed, {if exitCode = 1 then "see stderr for exception" else "likely due to a stack overflow or a bug"}."
s!"Server process for {fw.doc.meta.uri} crashed, {if exitCode = 1 then "see stderr for exception" else "likely due to a stack overflow or a bug in user's code"}."
return WorkerEvent.crashed err
loop
let task ← IO.asTask (loop $ ←read) Task.Priority.dedicated
@ -522,7 +522,7 @@ section MessageHandling
-- TODO Do fancier error handling, like in file worker?
| e => hOut.writeLspResponseError {
id := id
code := ErrorCode.workerCrashed
code := ErrorCode.internalError
message := s!"Failed to process request {id}: {e}"
}
-- If a definition is in a different, modified file, the ilean data should