Skip to content

Commit

Permalink
Add ErrorHandling for OpenWithEncoding function (#3438)
Browse files Browse the repository at this point in the history
* Add ErrorHandling

Signed-off-by: likhithanimma1 <[email protected]>

* Increase unit test coverage

Signed-off-by: likhithanimma1 <[email protected]>

---------

Signed-off-by: likhithanimma1 <[email protected]>
Co-authored-by: Fernando Rijo Cedeno <[email protected]>
  • Loading branch information
likhithanimma1 and zFernand0 committed Feb 17, 2025
1 parent 8baa860 commit dc10fe9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1393,4 +1393,17 @@ describe("openWithEncoding", () => {
expect(fetchSpoolAtUriMock).toHaveBeenCalledTimes(0);
expect(executeCommandMock).toHaveBeenCalledTimes(0);
});

it("should catch if error is thrown", async () => {
const testTree = new JobTree();
const spoolNode = new ZoweSpoolNode({ label: "SPOOL", collapsibleState: vscode.TreeItemCollapsibleState.None, spool: createIJobFile() });
const encoding: ZosEncoding = { kind: "other", codepage: "IBM-1147" };
const promptMock = jest.spyOn(SharedUtils, "promptForEncoding").mockResolvedValue(encoding);
jest.spyOn(JobFSProvider.instance, "fetchSpoolAtUri").mockImplementationOnce(() => {
throw new Error("testError");
});
await testTree.openWithEncoding(spoolNode);
expect(promptMock).toHaveBeenCalledWith(spoolNode);
expect(promptMock).toHaveBeenCalledTimes(1);
});
});
14 changes: 9 additions & 5 deletions packages/zowe-explorer/src/trees/job/JobTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,11 +1186,15 @@ export class JobTree extends ZoweTreeProvider<IZoweJobTreeNode> implements Types

public async openWithEncoding(node: IZoweJobTreeNode, encoding?: ZosEncoding): Promise<void> {
encoding ??= await SharedUtils.promptForEncoding(node);
if (encoding !== undefined) {
// Set the encoding, fetch the new contents with the encoding, and open the spool file.
await node.setEncoding(encoding);
await JobFSProvider.instance.fetchSpoolAtUri(node.resourceUri);
await vscode.commands.executeCommand("vscode.open", node.resourceUri);
try {
if (encoding !== undefined) {
// Set the encoding, fetch the new contents with the encoding, and open the spool file.
await node.setEncoding(encoding);
await JobFSProvider.instance.fetchSpoolAtUri(node.resourceUri);
await vscode.commands.executeCommand("vscode.open", node.resourceUri);
}
} catch (err) {
await AuthUtils.errorHandling(err, { profile: node.getProfile() });
}
}
}
Expand Down

0 comments on commit dc10fe9

Please sign in to comment.