Trace build error types (#1179)

This commit is contained in:
Jinbo Wang 2022-06-13 12:31:10 +08:00 committed by GitHub
parent 2de2206498
commit 2f3a9be2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 8 deletions

View File

@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. // Licensed under the MIT license.
import * as path from "path";
import * as vscode from "vscode"; import * as vscode from "vscode";
import { instrumentOperation, sendInfo, sendOperationError, setErrorCode } from "vscode-extension-telemetry-wrapper"; import { instrumentOperation, sendInfo, sendOperationError, setErrorCode } from "vscode-extension-telemetry-wrapper";
@ -56,8 +55,9 @@ async function handleBuildFailure(operationId: string, err: any, progressReporte
}); });
setErrorCode(error, Number(err)); setErrorCode(error, Number(err));
sendOperationError(operationId, "build", error); sendOperationError(operationId, "build", error);
const errorDiagnostics = traceErrorTypes(operationId);
if (!onBuildFailureProceed && err) { if (!onBuildFailureProceed && err) {
if (checkErrorsReportedByJavaExtension()) { if (errorDiagnostics) {
vscode.commands.executeCommand("workbench.actions.view.problems"); vscode.commands.executeCommand("workbench.actions.view.problems");
} }
@ -79,18 +79,28 @@ async function handleBuildFailure(operationId: string, err: any, progressReporte
return true; return true;
} }
function checkErrorsReportedByJavaExtension(): boolean { function traceErrorTypes(operationId: string): boolean {
const problems = vscode.languages.getDiagnostics() || []; const problems = vscode.languages.getDiagnostics() || [];
const errorTypes: {[key: string]: number} = {};
let errorCount = 0;
for (const problem of problems) { for (const problem of problems) {
const fileName = path.basename(problem[0].fsPath || ""); for (const diagnostic of problem[1]) {
if (fileName.endsWith(".java") || fileName === "pom.xml" || fileName.endsWith(".gradle")) { if (diagnostic.severity === vscode.DiagnosticSeverity.Error && diagnostic.source === "Java") {
if (problem[1].filter((diagnostic) => diagnostic.severity === vscode.DiagnosticSeverity.Error).length) { const errorCode = typeof diagnostic.code === 'object' ? String(diagnostic.code.value) : String(diagnostic.code);
return true; errorTypes[errorCode] = (errorTypes[errorCode] || 0) + 1;
errorCount++;
} }
} }
} }
return false; if (errorCount) {
sendInfo(operationId, {
buildErrorTypes: JSON.stringify(errorTypes),
buildErrorCount: errorCount,
});
}
return errorCount > 0;
} }
async function showFixSuggestions(operationId: string) { async function showFixSuggestions(operationId: string) {