Skip to content

Commit 98a2bbb

Browse files
edoardopirovanoaeisenberg
authored andcommitted
Limit error messages shown in popups to 2 lines
1 parent fb6bed6 commit 98a2bbb

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ export class DatabaseUI extends DisposableObject {
423423
if (failures.length) {
424424
const dirname = path.dirname(failures[0]);
425425
showAndLogErrorMessage(
426-
`Failed to delete unused databases:\n ${
427-
failures.join('\n ')
428-
}\n. To delete unused databases, please remove them manually from the storage folder ${dirname}.`
426+
`Failed to delete unused databases (${
427+
failures.join(', ')
428+
}).\nTo delete unused databases, please remove them manually from the storage folder ${dirname}.`
429429
);
430430
}
431431
};

extensions/ql-vscode/src/helpers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ export async function showAndLogErrorMessage(message: string, {
2929
items = [] as string[],
3030
fullMessage = undefined as (string | undefined)
3131
} = {}): Promise<string | undefined> {
32-
return internalShowAndLog(message, items, outputLogger, Window.showErrorMessage, fullMessage);
32+
return internalShowAndLog(dropLinesExceptInitial(message), items, outputLogger, Window.showErrorMessage, fullMessage);
3333
}
34+
35+
function dropLinesExceptInitial(message: string, n = 2) {
36+
return message.toString().split(/\r?\n/).slice(0, n).join('\n');
37+
}
38+
3439
/**
3540
* Show a warning message and log it to the console
3641
*

extensions/ql-vscode/src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ export class InterfaceManager extends DisposableObject {
634634
// If interpretation fails, accept the error and continue
635635
// trying to render uninterpreted results anyway.
636636
showAndLogErrorMessage(
637-
`Exception during results interpretation: ${e.message}. Will show raw results instead.`
637+
`Showing raw results instead of interpreted ones due to an error. ${e.message}`
638638
);
639639
}
640640
}

extensions/ql-vscode/src/run-queries.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,11 @@ export async function compileAndRunQueryAgainstDatabase(
640640
formattedMessages.push(formatted);
641641
qs.logger.log(formatted);
642642
}
643-
if (quickEval && formattedMessages.length <= 3) {
644-
showAndLogErrorMessage('Quick evaluation compilation failed: \n' + formattedMessages.join('\n'));
643+
if (quickEval && formattedMessages.length <= 2) {
644+
// If there are more than 2 error messages, they will not be displayed well in a popup
645+
// and will be trimmed by the function displaying the error popup. Accordingly, we only
646+
// try to show the errors if there are 2 or less, otherwise we direct the user to the log.
647+
showAndLogErrorMessage('Quick evaluation compilation failed: ' + formattedMessages.join('\n'));
645648
} else {
646649
showAndLogErrorMessage((quickEval ? 'Quick evaluation' : 'Query') + compilationFailedErrorTail);
647650
}

0 commit comments

Comments
 (0)