diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fb44ae4fe..5d9cff15a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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] diff --git a/docs/README.md b/docs/README.md index 90c5a92e3..ab8dd8957 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 `\_ +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 diff --git a/src/features/lightspeed/api.ts b/src/features/lightspeed/api.ts index 25d40171f..e7352c6f6 100644 --- a/src/features/lightspeed/api.ts +++ b/src/features/lightspeed/api.ts @@ -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 { @@ -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 { diff --git a/src/features/lightspeed/errors.ts b/src/features/lightspeed/errors.ts index be73db07e..08eeff0aa 100644 --- a/src/features/lightspeed/errors.ts +++ b/src/features/lightspeed/errors.ts @@ -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); } @@ -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( diff --git a/src/features/lightspeed/inlineSuggestions.ts b/src/features/lightspeed/inlineSuggestions.ts index 9ff3f4ad4..074e166ed 100644 --- a/src/features/lightspeed/inlineSuggestions.ts +++ b/src/features/lightspeed/inlineSuggestions.ts @@ -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; @@ -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.`, ); diff --git a/test/units/lightspeed/utils/handleApiError.test.ts b/test/units/lightspeed/utils/handleApiError.test.ts index 5ad5fdc62..52ee136c9 100644 --- a/test/units/lightspeed/utils/handleApiError.test.ts +++ b/test/units/lightspeed/utils/handleApiError.test.ts @@ -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", @@ -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, { @@ -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 // ---------------------------------