Skip to content

Commit

Permalink
Updates following peer review.
Browse files Browse the repository at this point in the history
  • Loading branch information
manstis committed Mar 29, 2024
1 parent f99821f commit bd29fb9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,12 @@ export class LightSpeedAPI {
} catch (error) {
const err = error as AxiosError;
const mappedError: IError = mapError(err);
vscode.window.showErrorMessage(mappedError.message ?? UNKNOWN_ERROR);
const errorMessage: string = mappedError.message ?? UNKNOWN_ERROR;
if (showInfoMessage) {
vscode.window.showErrorMessage(errorMessage);
} else {
console.error(errorMessage);
}
return {} as FeedbackResponseParams;
}
}
Expand Down Expand Up @@ -262,7 +267,6 @@ export class LightSpeedAPI {
} catch (error) {
const err = error as AxiosError;
const mappedError: IError = mapError(err);
vscode.window.showErrorMessage(mappedError.message ?? UNKNOWN_ERROR);
return mappedError;
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/features/lightspeed/contentMatchesWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
const noActiveSuggestionHtml = `
<html>
<body>
<p>Training matches cannot be retrieved. No active suggestion found.</p>
<p>Training matches will be displayed here after you accept an inline suggestion.</p>
</body>
</html>`;
if (
Expand Down Expand Up @@ -153,6 +153,15 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
} else if (typeof error.detail === "object") {
detail = JSON.stringify(error.detail, undefined, " ");
}
let htmlDetail: string | undefined = undefined;
if (detail !== undefined) {
htmlDetail = `
<details>
<summary><b>Detail:</b></summary>
<p>${detail}</p>
</details>
`;
}

const errorHtml = `
<html>
Expand All @@ -163,10 +172,7 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
<body>
<p>An error occurred trying to retrieve the training matches.</p>
<p><b>Message:</b> ${error.message}</p>
<details>
<summary><b>Detail:</b></summary>
<p>${detail}</p>
</details>
${htmlDetail}
</body>
</html>
`;
Expand Down
24 changes: 23 additions & 1 deletion test/units/lightspeed/contentmatches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("GetWebviewContent", () => {
assert.match(
res,
new RegExp(
"Training matches cannot be retrieved. No active suggestion found."
"Training matches will be displayed here after you accept an inline suggestion."
)
);
});
Expand Down Expand Up @@ -240,4 +240,26 @@ describe("GetWebviewContent", () => {
assert.match(res, new RegExp("An error occurred"));
assert.match(res, new RegExp('{\n "cheese": "edam"\n}'));
});

it("no suggestion with error - undefined", async function () {
const cmw = createContentMatchesWebview();
cmw.suggestionDetails = [
{
suggestion: "- name: foo\n my.mod:\n",
suggestionId: "bar",
} as ISuggestionDetails,
];
cmw.apiInstance.contentMatchesRequest = async (
inputData: ContentMatchesRequestParams // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<IError> => {
return createMatchErrorResponse(undefined);
};

const res = await cmw["getWebviewContent"]();
assert.match(
res,
new RegExp("An error occurred trying to retrieve the training matches.")
);
assert.doesNotMatch(res, new RegExp("<details>"));
});
});

0 comments on commit bd29fb9

Please sign in to comment.