diff --git a/packages/amazonq/src/lsp/chat/messages.ts b/packages/amazonq/src/lsp/chat/messages.ts index 147077c2647..56cd2d9ed27 100644 --- a/packages/amazonq/src/lsp/chat/messages.ts +++ b/packages/amazonq/src/lsp/chat/messages.ts @@ -295,10 +295,17 @@ export function registerMessageListeners( languageClient.onRequest( ShowDocumentRequest.method, async (params: ShowDocumentParams): Promise> => { - const uri = vscode.Uri.parse(params.uri) - const doc = await vscode.workspace.openTextDocument(uri) - await vscode.window.showTextDocument(doc, { preview: false }) - return params + try { + const uri = vscode.Uri.parse(params.uri) + const doc = await vscode.workspace.openTextDocument(uri) + await vscode.window.showTextDocument(doc, { preview: false }) + return params + } catch (e) { + return new ResponseError( + LSPErrorCodes.RequestFailed, + `Failed to open document: ${(e as Error).message}` + ) + } } )