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

Error retouch #848

Merged
merged 3 commits into from
Jun 20, 2024
Merged
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
17 changes: 8 additions & 9 deletions src/__tests__/unit/util/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ import {parseIEProcessArgs, parseIfDiffArgs} from '../../../util/args';

import {STRINGS} from '../../../config';

const {CliInputError, CliSourceFileError} = ERRORS;
const {CliSourceFileError, ParseCliParamsError} = ERRORS;

const {
MANIFEST_IS_MISSING,
FILE_IS_NOT_YAML,
TARGET_IS_NOT_YAML,
INVALID_TARGET,
SOURCE_IS_NOT_YAML,
Expand All @@ -106,8 +105,8 @@ describe('util/args: ', () => {
try {
parseIEProcessArgs();
} catch (error) {
expect(error).toBeInstanceOf(CliInputError);
expect(error).toEqual(new CliInputError(MANIFEST_IS_MISSING));
expect(error).toBeInstanceOf(ParseCliParamsError);
expect(error).toEqual(new ParseCliParamsError(MANIFEST_IS_MISSING));
}

process.env.result = 'manifest-is-missing';
Expand Down Expand Up @@ -196,7 +195,7 @@ describe('util/args: ', () => {
parseIEProcessArgs();
} catch (error) {
expect(error).toBeInstanceOf(CliSourceFileError);
expect(error).toEqual(new CliSourceFileError(FILE_IS_NOT_YAML));
expect(error).toEqual(new CliSourceFileError(SOURCE_IS_NOT_YAML));
}
});

Expand Down Expand Up @@ -226,7 +225,7 @@ describe('util/args: ', () => {
parseIfDiffArgs();
} catch (error) {
if (error instanceof Error) {
expect(error).toEqual(new CliInputError(INVALID_TARGET));
expect(error).toEqual(new ParseCliParamsError(INVALID_TARGET));
}
}
});
Expand All @@ -239,7 +238,7 @@ describe('util/args: ', () => {
parseIfDiffArgs();
} catch (error) {
if (error instanceof Error) {
expect(error).toEqual(new CliInputError(TARGET_IS_NOT_YAML));
expect(error).toEqual(new ParseCliParamsError(TARGET_IS_NOT_YAML));
}
}
});
Expand All @@ -260,7 +259,7 @@ describe('util/args: ', () => {
parseIfDiffArgs();
} catch (error) {
if (error instanceof Error) {
expect(error).toEqual(new CliInputError(SOURCE_IS_NOT_YAML));
expect(error).toEqual(new ParseCliParamsError(SOURCE_IS_NOT_YAML));
}
}
});
Expand All @@ -282,7 +281,7 @@ describe('util/args: ', () => {
parseIfDiffArgs();
} catch (error) {
if (error instanceof Error) {
expect(error).toEqual(new CliInputError('mock-error'));
expect(error).toEqual(new ParseCliParamsError('mock-error'));
}
}
});
Expand Down
3 changes: 1 addition & 2 deletions src/config/strings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {ManifestParameter} from '../types/manifest';

export const STRINGS = {
FILE_IS_NOT_YAML: 'Provided manifest is not in yaml format.',
MANIFEST_IS_MISSING: 'Manifest is missing.',
MISSING_METHOD: "Initalization param 'method' is missing.",
MISSING_PATH: "Initalization param 'path' is missing.",
Expand Down Expand Up @@ -49,7 +48,7 @@ You have not selected an output method. To see your output data, you can choose
--output <savepath>: this will save your output data to the given filepath (do not provide file extension)
Note that for the '--output' option you also need to define the output type in your manifest file. See https://if.greensoftware.foundation/major-concepts/manifest-file#initialize`,
SOURCE_IS_NOT_YAML: 'Given source file is not in yaml format.',
TARGET_IS_NOT_YAML: 'Given target is not in yaml format.',
TARGET_IS_NOT_YAML: 'Given target file is not in yaml format.',
INVALID_TARGET: 'Target is invalid.',
INVALID_SOURCE: 'Source is invalid.',
UNSUPPORTED_ERROR: (errorName: string) =>
Expand Down
16 changes: 5 additions & 11 deletions src/util/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ import {CONFIG, STRINGS} from '../config';
import {IFDiffArgs, IEArgs, ProcessArgsOutputs} from '../types/process-args';
import {LoadDiffParams} from '../types/util/args';

const {
CliInputError,
ParseCliParamsError,
CliTargetFileError,
CliSourceFileError,
} = ERRORS;
const {ParseCliParamsError, CliTargetFileError, CliSourceFileError} = ERRORS;

const {IE, IF_DIFF} = CONFIG;

const {
FILE_IS_NOT_YAML,
MANIFEST_IS_MISSING,
NO_OUTPUT,
SOURCE_IS_NOT_YAML,
Expand All @@ -37,7 +31,7 @@ const validateAndParseProcessArgs = () => {
return parse<IEArgs>(IE.ARGS, IE.HELP);
} catch (error) {
if (error instanceof Error) {
throw new CliInputError(error.message);
throw new ParseCliParamsError(error.message);
}

throw error;
Expand All @@ -63,7 +57,7 @@ const prependFullFilePath = (filePath: string) => {
* 3. If output params are missing, warns user about it.
* 3. Otherwise checks if `manifest` param is there, then processes with checking if it's a yaml file.
* If it is, then returns object containing full path.
* 4. If params are missing or invalid, then rejects with `CliInputError`.
* 4. If params are missing or invalid, then rejects with `ParseCliParamsError`.
*/
export const parseIEProcessArgs = (): ProcessArgsOutputs => {
const {
Expand Down Expand Up @@ -91,7 +85,7 @@ export const parseIEProcessArgs = (): ProcessArgsOutputs => {
};
}

throw new CliSourceFileError(FILE_IS_NOT_YAML);
throw new CliSourceFileError(SOURCE_IS_NOT_YAML);
}

throw new CliSourceFileError(MANIFEST_IS_MISSING);
Expand Down Expand Up @@ -140,5 +134,5 @@ export const parseIfDiffArgs = () => {
throw new CliTargetFileError(TARGET_IS_NOT_YAML);
}

throw new CliInputError(INVALID_TARGET);
throw new ParseCliParamsError(INVALID_TARGET);
};