From 9e2ab9051ae425a9ced159246e8b5cfa0cf03e39 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 15 Jan 2025 17:05:05 -0500 Subject: [PATCH] clean up error handling code --- .../DocumentationPreviewEditor.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/documentation/DocumentationPreviewEditor.ts b/src/documentation/DocumentationPreviewEditor.ts index 6385adbd..ae878323 100644 --- a/src/documentation/DocumentationPreviewEditor.ts +++ b/src/documentation/DocumentationPreviewEditor.ts @@ -205,23 +205,23 @@ export class DocumentationPreviewEditor implements vscode.Disposable { }, }); } catch (error) { - if (!(error instanceof ResponseError)) { + // Update the preview editor to reflect what error occurred + let errorMessage = "An internal error occurred"; + if (error instanceof ResponseError) { + if (error.code === LSPErrorCodes.RequestCancelled) { + // We can safely ignore cancellations + return undefined; + } + if (error.code === LSPErrorCodes.RequestFailed) { + errorMessage = error.message; + } + this.context.outputChannel.log( + `SourceKit-LSP request "${DocCDocumentationRequest.method}" failed:` + ); + this.context.outputChannel.log(JSON.stringify(error.toJson(), undefined, 2)); + } else { this.context.outputChannel.log("failed to convert documentation:"); this.context.outputChannel.log(`${error}`); - return; - } - if (error.code === LSPErrorCodes.RequestCancelled) { - // We can safely ignore cancellations - return undefined; - } - this.context.outputChannel.log( - `SourceKit-LSP request "${DocCDocumentationRequest.method}" failed:` - ); - this.context.outputChannel.log(JSON.stringify(error.toJson(), undefined, 2)); - // Update the preview editor to reflect what error occurred - let errorMessage = "An internal error occurred in SourceKit-LSP"; - if (error.code === LSPErrorCodes.RequestFailed) { - errorMessage = error.message; } this.postMessage({ type: "update-content",