Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standardizing error handling #2062

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

All notable changes to the Zowe CLI package will be documented in this file.

## `8.0.0-next.202402261705`
## Recent Changes

- BugFix: Update error handling in zosfiles to resemble that in zosjobs. [#2062](https://github.com/zowe/zowe-cli/pull/2062)

## `8.0.0-next.202402261705`
- BugFix: Updated additional dependencies for technical currency. [#2061](https://github.com/zowe/zowe-cli/pull/2061)
- BugFix: Updated engine to Node 16.7.0. [#2061](https://github.com/zowe/zowe-cli/pull/2061)

Expand Down Expand Up @@ -72,7 +75,7 @@ LTS Breaking: Removed the following previously deprecated items: [#1981](https:/
## `8.0.0-next.202311132045`

- Major: First major version bump for V3

## `7.23.3`
ATorrise marked this conversation as resolved.
Show resolved Hide resolved

- BugFix: Fixed race condition in `config convert-profiles` command that may fail to delete secure values for old profiles
Expand All @@ -88,7 +91,6 @@ LTS Breaking: Removed the following previously deprecated items: [#1981](https:/
## `7.23.0`

- BugFix: Update zos-files copy dsclp system tests to include large mock files.

## `7.22.0`

- Enhancement: Hid the progress bar if `CI` environment variable is set, or if `FORCE_COLOR` environment variable is set to `0`. [#1845](https://github.com/zowe/zowe-cli/issues/1845)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("Upload directory to PDS", () => {
it("should fail when local directory does not exist", async () => {
const shellScript = path.join(__dirname, "__scripts__", "command", "command_upload_dtp.sh");
const response = runCliScript(shellScript, TEST_ENVIRONMENT, ["localDirThatDoesNotExist", "mf.data.set"]);
expect(stripNewLines(response.stderr.toString())).toContain("no such file or directory, lstat");
expect(stripNewLines(response.stderr.toString())).toContain("no such file or directory");
expect(stripNewLines(response.stderr.toString())).toContain("localDirThatDoesNotExist");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("Upload file to data set", () => {
it("should fail when local file does not exist", async () => {
const shellScript = path.join(__dirname, "__scripts__", "command", "command_upload_ftds.sh");
const response = runCliScript(shellScript, TEST_ENVIRONMENT, ["localFileThatDoesNotExist", "data.set.name"]);
expect(stripNewLines(response.stderr.toString())).toContain("no such file or directory, lstat");
expect(stripNewLines(response.stderr.toString())).toContain("File does not exist or is not accessible");
expect(stripNewLines(response.stderr.toString())).toContain("localFileThatDoesNotExist");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@

import { Upload } from "@zowe/zos-files-for-zowe-sdk";
import { UNIT_TEST_ZOSMF_PROF_OPTS } from "../../../../../../../__tests__/__src__/mocks/ZosmfProfileMock";

import DirToPdsHandler from "../../../../../src/zosfiles/upload/dtp/DirToPds.handler";
describe("Upload dir-to-pds handler", () => {
describe("process method", () => {
it("should upload a directory to a PDS if requested", async () => {
// Require the handler and create a new instance
const handlerReq = require("../../../../../src/zosfiles/upload/dtp/DirToPds.handler");
const handler = new handlerReq.default();
const inputdir = "test-dir";
const dataSetName = "testing";
let handler: DirToPdsHandler;
const inputdir = "test-dir";
const dataSetName = "testing";
beforeEach(() => {
jest.resetAllMocks();
handler = new DirToPdsHandler();
(handler as any).checkDirectoryExistence = jest.fn().mockResolvedValue(undefined);
});

it("should upload a directory to a PDS if requested", async () => {
// Vars populated by the mocked function
let error;
let apiMessage = "";
Expand Down Expand Up @@ -94,12 +97,63 @@ describe("Upload dir-to-pds handler", () => {
expect(logMessage).toMatchSnapshot();
});

it("should not attempt to upload a dir that hasn't been found", async () => {
(handler as any).checkDirectoryExistence = jest.fn().mockRejectedValue(new Error("Failed to access directory"));
// Vars populated by the mocked function
let error;
let apiMessage = "";
let jsonObj;
let logMessage = "";

// Mock the submit JCL function
Upload.dirToPds = jest.fn();

try {
// Invoke the handler with a full set of mocked arguments and response functions
await handler.process({
arguments: {
$0: "fake",
_: ["fake"],
inputdir,
dataSetName,
...UNIT_TEST_ZOSMF_PROF_OPTS
},
response: {
data: {
setMessage: jest.fn((setMsgArgs) => {
apiMessage = setMsgArgs;
}),
setObj: jest.fn((setObjArgs) => {
jsonObj = setObjArgs;
})
},
console: {
log: jest.fn((logArgs) => {
logMessage += "\n" + logArgs;
}),
error: jest.fn((logArgs) => {
logMessage += "\n" + logArgs;
})
},
progress: {
startBar: jest.fn(),
endBar: jest.fn()
}
}
} as any);
} catch (e) {
error = e;
}

expect(error).toBeDefined();
expect(error.message).toContain("Failed to access directory");
expect(Upload.dirToPds).toHaveBeenCalledTimes(0);
expect(jsonObj).toMatchSnapshot();
expect(apiMessage).toMatchSnapshot();
expect(logMessage).toMatchSnapshot();
});

it("should upload a directory to a PDS in binary format if requested", async () => {
// Require the handler and create a new instance
const handlerReq = require("../../../../../src/zosfiles/upload/dtp/DirToPds.handler");
const handler = new handlerReq.default();
const inputdir = "test-dir";
const dataSetName = "testing";
const binary = true;

// Vars populated by the mocked function
Expand Down Expand Up @@ -178,11 +232,6 @@ describe("Upload dir-to-pds handler", () => {
});

it("should upload a directory to a PDS in record format if requested", async () => {
// Require the handler and create a new instance
const handlerReq = require("../../../../../src/zosfiles/upload/dtp/DirToPds.handler");
const handler = new handlerReq.default();
const inputdir = "test-dir";
const dataSetName = "testing";
const record = true;

// Vars populated by the mocked function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,103 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS if requested 1`] = `undefined`;
exports[`Upload dir-to-pds handler process method should not attempt to upload a dir that hasn't been found 1`] = `undefined`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS if requested 2`] = `""`;
exports[`Upload dir-to-pds handler process method should not attempt to upload a dir that hasn't been found 2`] = `""`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS if requested 3`] = `
exports[`Upload dir-to-pds handler process method should not attempt to upload a dir that hasn't been found 3`] = `
"
success: true
from:  test-dir
to:  testing
Error: Failed to access directory"
`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS if requested 1`] = `
Object {
"apiResponse": Array [
Object {
"from": "test-dir",
"success": true,
"to": "testing",
},
Object {
"from": "testfrom",
"success": false,
"to": "testto",
},
Object {
"from": "dummy",
"success": undefined,
"to": "nowhere",
},
],
"commandResponse": "uploaded",
"success": false,
}
`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS if requested 2`] = `""`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS if requested 3`] = `
"
uploaded"
`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS in binary format if requested 1`] = `undefined`;
exports[`Upload dir-to-pds handler process method should upload a directory to a PDS in binary format if requested 1`] = `
Object {
"apiResponse": Array [
Object {
"from": "test-dir",
"success": true,
"to": "testing",
},
Object {
"from": "testfrom",
"success": false,
"to": "testto",
},
Object {
"from": "dummy",
"success": undefined,
"to": "nowhere",
},
],
"commandResponse": "uploaded",
"success": false,
}
`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS in binary format if requested 2`] = `""`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS in binary format if requested 3`] = `
"
success: true
from:  test-dir
to:  testing

"
uploaded"
`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS in record format if requested 1`] = `undefined`;
exports[`Upload dir-to-pds handler process method should upload a directory to a PDS in record format if requested 1`] = `
Object {
"apiResponse": Array [
Object {
"from": "test-dir",
"success": true,
"to": "testing",
},
Object {
"from": "testfrom",
"success": false,
"to": "testto",
},
Object {
"from": "dummy",
"success": undefined,
"to": "nowhere",
},
],
"commandResponse": "uploaded",
"success": false,
}
`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS in record format if requested 2`] = `""`;

exports[`Upload dir-to-pds handler process method should upload a directory to a PDS in record format if requested 3`] = `
"
success: true
from:  test-dir
to:  testing

"
uploaded"
`;
Loading
Loading