Skip to content

Commit a4f9411

Browse files
committed
Add error handling to previewQueryHelp
1 parent f7089cc commit a4f9411

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

extensions/ql-vscode/src/extension.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,21 @@ async function activateWithInstalledDistribution(
498498
): Promise<void> {
499499
const path = selectedQuery ? selectedQuery.path : window.activeTextEditor!.document.uri.fsPath;
500500
if(path) {
501+
// Get path of temporary 'qh-markdown' directory in extension context
501502
const tempDirPath = `${getContextStoragePath(ctx)}/qh-markdown/`;
503+
// Get library name and query file name in the format 'libname/queryname.md
502504
const mdFilePath = path.split('/').slice(-2).join('/').replace('.qhelp', '.md');
503-
const absolutePath = `${tempDirPath}${mdFilePath}`;
504-
const uri = Uri.file(absolutePath);
505-
await cliServer.generateQueryHelp(path , 'markdown', absolutePath);
506-
await commands.executeCommand('markdown.showPreviewToSide', uri);
505+
const absolutePathToMd = `${tempDirPath}${mdFilePath}`;
506+
const uri = Uri.file(absolutePathToMd);
507+
try {
508+
await cliServer.generateQueryHelp(path , 'markdown', absolutePathToMd);
509+
await commands.executeCommand('markdown.showPreviewToSide', uri);
510+
} catch (err) {
511+
const errorMessage = err.message.includes('Generating qlhelp in markdown') ? (
512+
`Could not generate markdown from ${path}: Bad formatting in .qhelp file.`
513+
) : `Could not open a preview of the generated file (${absolutePathToMd}).`;
514+
void helpers.showAndLogErrorMessage(errorMessage);
515+
}
507516
}
508517
}
509518

0 commit comments

Comments
 (0)