Skip to content

Commit ae23fe2

Browse files
fix: update proper error messages (#87)
Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
1 parent 5f382ce commit ae23fe2

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/components/Context/Context.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Box, Text } from 'ink';
44
import ContextError from './contexterror';
55
import { useContextFile, MissingArgumentstError } from '../../hooks/context';
66
import { SpecificationFile } from '../../hooks/validation';
7-
7+
import { ARGUMENTS } from '../../messages';
88
export const ListContexts: React.FunctionComponent = () => {
99
const { response, error } = useContextFile().list();
1010

@@ -40,8 +40,10 @@ export const ShowCurrentContext: React.FunctionComponent = () => {
4040
export const AddContext: React.FunctionComponent<{ options: any, args: string[] }> = ({ args }) => {
4141
const [key, path] = args;
4242

43-
if (!key || !path) {
44-
return <ContextError error={new MissingArgumentstError()} />;
43+
if (!key) {
44+
return <ContextError error={new MissingArgumentstError(ARGUMENTS.CONTEXT_NAME, ARGUMENTS.CONTEXT)} />;
45+
} else if (!path) {
46+
return <ContextError error={new MissingArgumentstError(ARGUMENTS.SPEC_PATH, ARGUMENTS.CONTEXT)} />;
4547
}
4648

4749
const { response, error } = useContextFile().addContext(key, new SpecificationFile(path));
@@ -57,7 +59,7 @@ export const SetCurrent: React.FunctionComponent<{ options: any, args: string[]
5759
const [key,] = args;
5860

5961
if (!key) {
60-
return <ContextError error={new MissingArgumentstError()} />;
62+
return <ContextError error={new MissingArgumentstError(ARGUMENTS.CONTEXT_NAME, ARGUMENTS.CONTEXT)} />;
6163
}
6264

6365
const { response, error } = useContextFile().setCurrent(key);
@@ -77,7 +79,7 @@ export const RemoveContext: React.FunctionComponent<{ options: any, args: string
7779
const [key] = args;
7880

7981
if (!key) {
80-
return <ContextError error={new MissingArgumentstError()} />;
82+
return <ContextError error={new MissingArgumentstError(ARGUMENTS.CONTEXT_NAME, ARGUMENTS.CONTEXT)} />;
8183
}
8284

8385
const { response, error } = useContextFile().deleteContext(key);

src/hooks/context/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export class MissingCurrentContextError extends Error {
3535
}
3636

3737
export class MissingArgumentstError extends Error {
38-
constructor() {
38+
constructor(argument: string, command: string) {
3939
super();
40-
this.message = messages.MISSING_ARGUMENTS;
40+
this.message = messages.MISSING_ARGUMENTS(argument, command);
4141
}
4242
}
4343

src/messages.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const CONTEXT_NOT_FOUND = (contextName: string) => `Context ${contextName
55

66
export const MISSING_CURRENT_CONTEXT = 'No context is set as current, please set a current context.';
77

8-
export const MISSING_ARGUMENTS = 'Missing arguments.';
8+
export const MISSING_ARGUMENTS = (argument: string, command: string) => `Missing arguments: ${argument}\nrun asyncapi ${command} --help to know more.`;
99

1010
export const NEW_CONTEXT_ADDED = (contextName: string) => `New context added.\n\nYou can set it as your current context: asyncapi context use ${contextName}\nYou can use this context when needed by passing ${contextName} as a parameter: asyncapi valiate ${contextName}`;
1111

@@ -21,3 +21,9 @@ export const NO_SPEC_FOUND = (command: string) => `${FALLBACK_MESSAGES[command]}
2121
export const FALLBACK_MESSAGES: {[name: string]: string} = {
2222
validate: 'Unable to perform validation. Specify what AsyncAPI file should be validated.'
2323
};
24+
25+
export const ARGUMENTS = {
26+
CONTEXT_NAME: 'context-name',
27+
SPEC_PATH: 'spec-path',
28+
CONTEXT: 'context'
29+
};

0 commit comments

Comments
 (0)