diff --git a/native/c/zjb.cpp b/native/c/zjb.cpp index 0b0a4516e..f58c7f8f6 100644 --- a/native/c/zjb.cpp +++ b/native/c/zjb.cpp @@ -8,6 +8,7 @@ * Copyright Contributors to the Zowe Project. * */ + #include #include #include diff --git a/packages/vsce/CHANGELOG.md b/packages/vsce/CHANGELOG.md index 5eed3ac6c..5f46139cf 100644 --- a/packages/vsce/CHANGELOG.md +++ b/packages/vsce/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to the "zowex-vsce" extension will be documented in this fil Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## Recent Changes + +- Fixed error handling of methods in `SshMvsApi` class so that errors are thrown and propagated to extenders. [#917](https://github.com/zowe/zowex/issues/917) + ## `0.5.0` - **Breaking:** Renamed contributed setting IDs from `zowe-native-proto` to `zowex`. All references to `zowe-native-proto` should be replaced with `zowex` in VS Code `settings.json` files. [#831](https://github.com/zowe/zowex/issues/831) diff --git a/packages/vsce/src/api/SshCommonApi.ts b/packages/vsce/src/api/SshCommonApi.ts index 89be712e4..966bb6360 100644 --- a/packages/vsce/src/api/SshCommonApi.ts +++ b/packages/vsce/src/api/SshCommonApi.ts @@ -180,4 +180,13 @@ export class SshCommonApi implements MainframeInteraction.ICommon { // All attempts failed return undefined; } + + /** + * Converts an `ImperativeError` to a plain JS error to avoid losing additional details + * @param maybeError The thrown error to convert + */ + protected buildRequestError(maybeError: unknown): Error | unknown { + if (!(maybeError instanceof ImperativeError)) return maybeError; + return new Error(`${maybeError.message}\n${maybeError.additionalDetails}`); + } } diff --git a/packages/vsce/src/api/SshMvsApi.ts b/packages/vsce/src/api/SshMvsApi.ts index 4b3c96286..de332c0f8 100644 --- a/packages/vsce/src/api/SshMvsApi.ts +++ b/packages/vsce/src/api/SshMvsApi.ts @@ -17,7 +17,6 @@ import { type AttributeInfo, type DataSetAttributesProvider, type DsInfo, - Gui, type IAttributesProvider, imperative, type MainframeInteraction, @@ -285,31 +284,20 @@ export class SshMvsApi extends SshCommonApi implements MainframeInteraction.IMvs attributes: datasetAttributes, }); } catch (error) { - if (error instanceof imperative.ImperativeError) { - Gui.errorMessage(error.additionalDetails); - } + throw this.buildRequestError(error); } - return this.buildZosFilesResponse(response, response.success); + return this.buildZosFilesResponse(response); } public async createDataSetMember( dataSetName: string, _options?: zosfiles.IUploadOptions, ): Promise { - let response: ds.CreateMemberResponse = { success: false }; - try { - response = await (await this.client).ds.createMember({ - dsname: dataSetName, - overwrite: true, // Overwrite detection already handled on client side - }); - if (!response.success) { - Gui.errorMessage(`Failed to create data set member: ${dataSetName}`); - } - } catch (error) { - Gui.errorMessage(`Failed to create data set member: ${dataSetName}`); - Gui.errorMessage(`Error: ${error}`); - } - return this.buildZosFilesResponse(response, response.success); + const response = await (await this.client).ds.createMember({ + dsname: dataSetName, + overwrite: true, // Overwrite detection already handled on client side + }); + return this.buildZosFilesResponse(response); } public async allocateLikeDataSet( @@ -335,9 +323,7 @@ export class SshMvsApi extends SshCommonApi implements MainframeInteraction.IMvs dsnameBefore: currentDataSetName, dsnameAfter: newDataSetName, }); - return this.buildZosFilesResponse({ - success: response.success, - }); + return this.buildZosFilesResponse(response); } public async renameDataSetMember( @@ -350,9 +336,7 @@ export class SshMvsApi extends SshCommonApi implements MainframeInteraction.IMvs memberBefore, memberAfter, }); - return this.buildZosFilesResponse({ - success: response.success, - }); + return this.buildZosFilesResponse(response); } public async hMigrateDataSet(_dataSetName: string): Promise { @@ -360,18 +344,9 @@ export class SshMvsApi extends SshCommonApi implements MainframeInteraction.IMvs } public async hRecallDataSet(dataSetName: string): Promise { - let response: ds.RestoreDatasetResponse = { success: false }; - try { - response = await (await this.client).ds.restoreDataset({ - dsname: dataSetName, - }); - if (!response.success) { - Gui.errorMessage(`Failed to restore dataset ${dataSetName}`); - } - } catch (error) { - Gui.errorMessage(`Failed to restore dataset ${dataSetName}`); - Gui.errorMessage(`Error: ${error}`); - } + const response = await (await this.client).ds.restoreDataset({ + dsname: dataSetName, + }); return this.buildZosFilesResponse(response); } @@ -382,13 +357,11 @@ export class SshMvsApi extends SshCommonApi implements MainframeInteraction.IMvs const response = await (await this.client).ds.deleteDataset({ dsname: dataSetName, }); - return this.buildZosFilesResponse({ - success: response.success, - }); + return this.buildZosFilesResponse(response); } // biome-ignore lint/suspicious/noExplicitAny: apiResponse has no strong type private buildZosFilesResponse(apiResponse: any, success = true, errorText?: string): zosfiles.IZosFilesResponse { - return { apiResponse, commandResponse: "", success, errorMessage: errorText }; + return { apiResponse, commandResponse: "", success: apiResponse?.success ?? success, errorMessage: errorText }; } } diff --git a/packages/vsce/src/api/SshUssApi.ts b/packages/vsce/src/api/SshUssApi.ts index 9eff2bbef..81b185d87 100644 --- a/packages/vsce/src/api/SshUssApi.ts +++ b/packages/vsce/src/api/SshUssApi.ts @@ -130,7 +130,7 @@ export class SshUssApi extends SshCommonApi implements MainframeInteraction.IUss force: force, }); - return Buffer.from(JSON.stringify(this.buildZosFilesResponse(response, response.success))); + return Buffer.from(JSON.stringify(this.buildZosFilesResponse(response))); } public async create(ussPath: string, type: string, mode?: string | undefined): Promise { @@ -139,7 +139,7 @@ export class SshUssApi extends SshCommonApi implements MainframeInteraction.IUss isDir: type === "directory", permissions: mode, }); - return this.buildZosFilesResponse(response, response.success); + return this.buildZosFilesResponse(response); } public async delete(ussPath: string, recursive?: boolean | undefined): Promise { @@ -147,7 +147,7 @@ export class SshUssApi extends SshCommonApi implements MainframeInteraction.IUss fspath: ussPath, recursive: recursive, }); - return this.buildZosFilesResponse(response, response.success); + return this.buildZosFilesResponse(response); } public async move(oldPath: string, newPath: string): Promise { @@ -162,7 +162,7 @@ export class SshUssApi extends SshCommonApi implements MainframeInteraction.IUss source: currentUssPath, target: newUssPath, }); - return this.buildZosFilesResponse(response, response.success); + return this.buildZosFilesResponse(response); } public async getTag(ussPath: string): Promise { @@ -217,6 +217,6 @@ export class SshUssApi extends SshCommonApi implements MainframeInteraction.IUss // biome-ignore lint/suspicious/noExplicitAny: The apiResponse has no strong type private buildZosFilesResponse(apiResponse: any, success = true): zosfiles.IZosFilesResponse { - return { apiResponse, commandResponse: "", success }; + return { apiResponse, commandResponse: "", success: apiResponse?.success ?? success }; } }