Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine prompt informing users of errors #807

Merged
merged 3 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions src/errorReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,20 @@ export class ErrorReporter {
static async showErrorDialog(
error: ErrorEventInterface): Promise<void> {

const template = `<!-- Please delete any private information -->
**Version:**
${// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
vscode.extensions.getExtension('ms-edgedevtools.vscode-edge-devtools')?.packageJSON.version || 'N/A'}

**OS:**
<!-- Add your hosting platform e.g Microsoft Windows, WSL, MacOs or Linux -->

**Stack :**
${error.message}

**Additional context:**
<!-- Add any other context or about the problem or screenshots here. -->`;

// cannot do multiline due to:
// https://github.com/Microsoft/vscode/issues/48900
const answer = await vscode.window
.showErrorMessage(
`An error occurred: ${error.title} ${error.message}`,
...['File a bug']
.showWarningMessage(
`${error.title} ${error.message}`,
...['Check settings', 'Search issues']
);

if (answer === 'File a bug') {
let base = 'https://github.com/microsoft/vscode-edge-devtools/issues/new?';
const params: Map<string, string> = new Map<string, string>();

params.set('title',encodeURIComponent(`[${error.errorCode}] ${error.title}`));
params.set('body', encodeURIComponent(template));
params.set('labels', 'error');

// As this are GET request params there is no need to take out the last
// ampersand
params.forEach((value, key) => {
base += `${key}=${value}&`;
});
if (answer === 'Check settings') {
void vscode.commands.executeCommand('workbench.action.openSettings', '@ext:ms-edgedevtools.vscode-edge-devtools');
} else if (answer === 'Search issues') {
const searchUrl = `https://github.com/microsoft/vscode-edge-devtools/issues?q=is%3Aissue+is%3Aopen+${error.title}`;

void vscode.env.openExternal(vscode.Uri.parse(base));
void vscode.env.openExternal(vscode.Uri.parse(searchUrl));
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/devtoolsPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ describe("devtoolsPanel", () => {
dtp.DevToolsPanel.createOrShow(context, mockTelemetry, "", mockRuntimeConfig);

await hookedEvents.get("openInEditor")!(JSON.stringify(expectedRequest));
expect(mockVsCode.window.showErrorMessage).toHaveBeenCalled();
expect(mockVsCode.window.showWarningMessage).toHaveBeenCalled();
});

it("calls openTextDocument for onSocketCssMirrorContent", async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function createFakeVSCode() {
showQuickPick: jest.fn().mockResolvedValue(null),
showTextDocument: jest.fn(),
showInformationMessage: jest.fn(),
showWarningMessage: jest.fn().mockResolvedValue(new Promise(()=>{})),
showWarningMessage: jest.fn().mockResolvedValue({}),
},
workspace: {
createFileSystemWatcher: jest.fn(),
Expand Down