Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/npm_and_yarn-1d3c33138b
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonlhart committed Sep 7, 2024
2 parents fbb1fa2 + e0596a1 commit b6dd385
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exclude: >
minimum_pre_commit_version: 2.9.0 # types_or
repos:
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.13.1
rev: v8.13.3
hooks:
- id: cspell
# name: Spell check with cspell
Expand Down Expand Up @@ -174,7 +174,7 @@ repos:
docs/development/webview_guide.md
$
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.16.0
rev: v9.17.0
hooks:
- id: commitlint
stages: [commit-msg]
36 changes: 35 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,41 @@ to get started with developing the extension.

## Contact

- [Ansible Developer Tools matrix channel](https://matrix.to/#/#devtools:ansible.im)
We welcome your feedback, questions and ideas. Here's how to reach the
community.

### Forum

Join the [Ansible Forum](https://forum.ansible.com) as a single starting point
and our default communication platform for questions and help, development
discussions, events, and much more.
[Register](https://forum.ansible.com/signup?) to join the community. Search by
categories and tags to find interesting topics or start a new one; subscribe
only to topics you need!

- [Get Help](https://forum.ansible.com/c/help/6): get help or help others.
Please add appropriate tags if you start new discussions, for example
`vscode-ansible`.
- [Posts tagged with 'vscode-ansible'](https://forum.ansible.com/tag/vscode-ansible):
subscribe to participate in project-related conversations.
- [Social Spaces](https://forum.ansible.com/c/chat/4): gather and interact with
fellow enthusiasts.
- [News & Announcements](https://forum.ansible.com/c/news/5): track project-wide
announcements including social events. The
[Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn),
which is used to announce releases and important changes, can also be found
here.

See
`Navigating the Ansible forum <https://forum.ansible.com/t/navigating-the-ansible-forum-tags-categories-and-concepts/39>`\_
for some practical advice on finding your way around.

### Matrix

- [#devtools:ansible.im](https://matrix.to/#/#devtools:ansible.im): a chat
channel via the Matrix protocol. See the
[Ansible communication guide](https://docs.ansible.com/ansible/devel/community/communication.html#real-time-chat)
to learn how to join.

## Credit

Expand Down
6 changes: 4 additions & 2 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ export class LightSpeedAPI {
const err = error as AxiosError;
const mappedError: IError = await mapError(err);
if (!(await this._oneClickTrialProvider.showPopup(mappedError))) {
vscode.window.showErrorMessage(mappedError.message ?? UNKNOWN_ERROR);
vscode.window.showErrorMessage(
`${mappedError.message ?? UNKNOWN_ERROR} ${mappedError.detail ?? ""}`,
);
}
return {} as CompletionResponseParams;
} finally {
Expand Down Expand Up @@ -233,7 +235,7 @@ export class LightSpeedAPI {
} catch (error) {
const err = error as AxiosError;
const mappedError: IError = await mapError(err);
const errorMessage: string = mappedError.message ?? UNKNOWN_ERROR;
const errorMessage: string = `${mappedError.message ?? UNKNOWN_ERROR} ${mappedError.detail ?? ""}`;
if (showInfoMessage) {
vscode.window.showErrorMessage(errorMessage);
} else {
Expand Down
35 changes: 30 additions & 5 deletions src/features/lightspeed/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,38 @@ class Errors {
});

if (e) {
const responseErrorData = <
AxiosError<{ code?: string; message?: unknown }>
>err?.response?.data;

// If the Error does not have a default message use the payload message
let message = e.message;
if (message === undefined) {
const responseErrorData = <
AxiosError<{ code?: string; message?: string }>
>err?.response?.data;
message = Object.prototype.hasOwnProperty.call(
responseErrorData,
"message",
)
? (responseErrorData.message as string)
? responseErrorData.message
: "unknown";
}

let detail: string = "";
if (typeof responseErrorData.message == "string") {
detail = responseErrorData.message ?? "";
} else if (Array.isArray(responseErrorData.message)) {
const messages = responseErrorData.message as [];
messages.forEach((value: string, index: number) => {
detail =
detail +
"(" +
(index + 1) +
") " +
value +
(index < messages.length - 1 ? " " : "");
});
}

// Clone the Error to preserve the original definition
const detail = err.response?.data;
return new Error(e.code, message, detail, e.check);
}

Expand Down Expand Up @@ -259,6 +276,14 @@ ERRORS.addError(
),
);

ERRORS.addError(
418,
new Error(
"error__wca_instance_deleted",
"IBM watsonx Code Assistant instance associated with your Model Id has been deleted. Please contact your administrator.",
),
);

ERRORS.addError(
500,
new Error(
Expand Down
13 changes: 0 additions & 13 deletions src/features/lightspeed/inlineSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { IAnsibleFileType } from "../../interfaces/lightspeed";
import { getAnsibleFileType } from "../utils/ansible";
import { LightSpeedServiceSettings } from "../../interfaces/extensionSettings";
import { SuggestionDisplayed } from "./inlineSuggestion/suggestionDisplayed";
import { getAdditionalContext } from "./inlineSuggestion/additionalContext";

let inlineSuggestionData: InlineSuggestionEvent = {};
let inlineSuggestionDisplayTime: Date;
Expand Down Expand Up @@ -740,18 +739,6 @@ async function requestInlineSuggest(
completionData.model = userProvidedModel;
}

if (rhUserHasSeat) {
const additionalContext = getAdditionalContext(
parsedAnsibleDocument,
documentDirPath,
documentFilePath,
ansibleFileType,
vscode.workspace.workspaceFolders,
);
if (completionData.metadata) {
completionData.metadata.additionalContext = additionalContext;
}
}
console.log(
`[inline-suggestions] ${getCurrentUTCDateTime().toISOString()}: Completion request sent to Ansible Lightspeed.`,
);
Expand Down
46 changes: 45 additions & 1 deletion test/units/lightspeed/utils/handleApiError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("testing the error handling", () => {
assert.equal(error.message, "Bad Request response. Please try again.");
});

it("err Postprocessing error", () => {
it("err Preprocessing error", () => {
const error = mapError(
createError(400, {
code: "error__preprocess_invalid_yaml",
Expand All @@ -89,6 +89,34 @@ describe("testing the error handling", () => {
);
});

it("err Preprocessing error with simple detail", () => {
const error = mapError(
createError(400, {
code: "error__preprocess_invalid_yaml",
message: "A simple error.",
}),
);
assert.equal(
error.message,
"An error occurred pre-processing the inline suggestion due to invalid YAML. Please contact your administrator.",
);
assert.equal(error.detail, "A simple error.");
});

it("err Preprocessing error with complex detail", () => {
const error = mapError(
createError(400, {
code: "error__preprocess_invalid_yaml",
message: ["error 1", "error 2"],
}),
);
assert.equal(
error.message,
"An error occurred pre-processing the inline suggestion due to invalid YAML. Please contact your administrator.",
);
assert.equal(error.detail, "(1) error 1 (2) error 2");
});

it("err Feedback validation error", () => {
const error = mapError(
createError(400, {
Expand Down Expand Up @@ -288,6 +316,22 @@ describe("testing the error handling", () => {
});
// =================================

// =================================
// HTTP 418
// ---------------------------------
it("err WCA instance deleted", () => {
const error = mapError(
createError(418, {
code: "error__wca_instance_deleted",
}),
);
assert.equal(
error.message,
"IBM watsonx Code Assistant instance associated with your Model Id has been deleted. Please contact your administrator.",
);
});
// =================================

// =================================
// HTTP 429
// ---------------------------------
Expand Down

0 comments on commit b6dd385

Please sign in to comment.