| 272 | } |
| 273 | |
| 274 | class DefaultErrorHandler implements ErrorHandler { |
| 275 | |
| 276 | private restarts: number[]; |
| 277 | |
| 278 | constructor(private name: string) { |
| 279 | this.restarts = []; |
| 280 | } |
| 281 | |
| 282 | public error(_error: Error, _message: Message, count: number): ErrorAction { |
| 283 | if (count && count <= 3) { |
| 284 | return ErrorAction.Continue; |
| 285 | } |
| 286 | return ErrorAction.Shutdown; |
| 287 | } |
| 288 | public closed(): CloseAction { |
| 289 | this.restarts.push(Date.now()); |
| 290 | if (this.restarts.length < 5) { |
| 291 | return CloseAction.Restart; |
| 292 | } else { |
| 293 | let diff = this.restarts[this.restarts.length - 1] - this.restarts[0]; |
| 294 | if (diff <= 3 * 60 * 1000) { |
| 295 | Window.showErrorMessage(`The ${this.name} server crashed 5 times in the last 3 minutes. The server will not be restarted.`); |
| 296 | return CloseAction.DoNotRestart; |
| 297 | } else { |
| 298 | this.restarts.shift(); |
| 299 | return CloseAction.Restart; |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | export interface InitializationFailedHandler { |
| 306 | (error: ResponseError<InitializeError> | Error | any): boolean; |
nothing calls this directly
no outgoing calls
no test coverage detected