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

fix error in asyncapi optimize #1634

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 16 additions & 8 deletions src/commands/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,20 @@ export default class Optimize extends Command {
if (err.message.includes('Failed to download')) {
throw new Error('Proxy Connection Error: Unable to establish a connection to the proxy check hostName or PortNumber.');
} else {
this.error(
new ValidationError({
type: 'invalid-file',
filepath: filePath,
})
);
if(filePath){
this.error(
new ValidationError({
type: 'invalid-file',
filepath: filePath,
})
);
}else{
this.error(
new ValidationError({
type: 'no-spec-found'
})
);
}
}
}

Expand All @@ -88,8 +96,8 @@ export default class Optimize extends Command {
} catch (err) {
this.error(
new ValidationError({
type: 'invalid-file',
filepath: filePath,
type: 'invalid-syntax-file',
filepath: this.specFile.getFilePath(),
})
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/errors/validation-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type ErrorType = 'parser-error' | 'invalid-file' | 'no-spec-found';
type ErrorType = 'parser-error' | 'invalid-file' | 'no-spec-found' | 'invalid-syntax-file';

interface IValidationErrorInput {
type: ErrorType;
Expand All @@ -15,6 +15,9 @@ export class ValidationError extends Error {
if (error.type === 'invalid-file') {
this.message = `There is no file or context with name "${error.filepath}".`;
}
if (error.type === 'invalid-syntax-file') {
this.message = `Syntax Error in "${error.filepath}"`;
}
if (error.type === 'no-spec-found') {
this.message = 'Unable to perform validation. Specify what AsyncAPI file should be validated.\n\nThese are your options to specify in the CLI what AsyncAPI file should be used:\n- You can provide a path to the AsyncAPI file: asyncapi validate path/to/file/asyncapi.yml\n- You can also pass a saved context that points to your AsyncAPI file: asyncapi validate mycontext\n- In case you did not specify a context that you want to use, the CLI checks if there is a default context and uses it. To set default context run: asyncapi context use mycontext\n- In case you did not provide any reference to AsyncAPI file and there is no default context, the CLI detects if in your current working directory you have files like asyncapi.json, asyncapi.yaml, asyncapi.yml. Just rename your file accordingly.';
}
Expand Down
Loading