Improving error message when projects fail to load (#22786)

* Improving message when project fails to load

* Cleaning up string
This commit is contained in:
Benjin Dubishar
2023-04-20 14:00:43 -07:00
committed by GitHub
parent 8613176817
commit 2142c706b0
3 changed files with 18 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ export const SelectProjectFileActionName = localize('SelectProjectFileActionName
export const AllProjectTypes = localize('AllProjectTypes', "All Project Types");
export const ProviderNotFoundForProjectTypeError = (projectType: string): string => { return localize('UnknownProjectTypeError', "No provider was found for project type with id: '{0}'", projectType); };
export const RestartConfirmation = localize('dataworkspace.restartConfirmation', "Azure Data Studio needs to be restarted for the project to be added to the workspace. Restart now?");
export const ProjectsFailedToLoad = localize('dataworkspace.projectsFailedToLoad', "Some projects failed to load. To view more details, [open the developer console](command:workbench.action.toggleDevTools)");
export const projectFailedToLoad = (project: string, error: string) => { return localize('projectFailedToLoad', "Project '{0}' failed to load: {1} To view more details, [open the developer console](command:workbench.action.toggleDevTools).", project, error) };
export const fileDoesNotExist = (name: string): string => { return localize('fileDoesNotExist', "File '{0}' doesn't exist", name); };
export const projectNameNull = localize('projectNameNull', "Project name is null");
export const noPreviousData = (tableName: string): string => { return localize('noPreviousData', "Prior {0} for the current project will appear here, please run to see the results.", tableName); };

View File

@@ -91,3 +91,12 @@ export async function showInfoMessageWithLearnMoreLink(message: string, link: st
void vscode.env.openExternal(vscode.Uri.parse(link));
}
}
/**
* Consolidates on the error message string
*/
export function getErrorMessage(error: any): string {
return (error instanceof Error)
? (typeof error.message === 'string' ? error.message : '')
: typeof error === 'string' ? error : `${JSON.stringify(error, undefined, '\t')}`;
}

View File

@@ -6,9 +6,10 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { IWorkspaceService } from './interfaces';
import { dragAndDropNotSupported, onlyMovingOneFileIsSupported, ProjectsFailedToLoad, UnknownProjectsError } from './constants';
import { dragAndDropNotSupported, onlyMovingOneFileIsSupported, projectFailedToLoad, UnknownProjectsError } from './constants';
import { WorkspaceTreeItem } from 'dataworkspace';
import { TelemetryReporter } from './telemetry';
import { getErrorMessage } from './utils';
import Logger from './logger';
/**
@@ -54,7 +55,7 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<Worksp
const typeMetric: Record<string, number> = {};
let errorCount = 0;
let errorMessages: { project: vscode.Uri, errorMessage: string }[] = [];
for (const project of projects) {
try {
const projectProvider = await this._workspaceService.getProjectProvider(project);
@@ -79,13 +80,15 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<Worksp
});
});
} catch (e) {
errorCount++;
errorMessages.push({ project: project, errorMessage: getErrorMessage(e) });
console.error(e.message);
}
}
if (errorCount > 0) {
void vscode.window.showErrorMessage(ProjectsFailedToLoad);
if (errorMessages.length > 0) {
for (let error of errorMessages) {
void vscode.window.showErrorMessage(projectFailedToLoad(path.basename(error.project.fsPath), error.errorMessage + (error.errorMessage.endsWith('.') ? '' : '.')));
}
}
TelemetryReporter.sendMetricsEvent(typeMetric, 'OpenWorkspaceProjectTypes');