Skip to content

Commit

Permalink
fix error in asyncapi optimize
Browse files Browse the repository at this point in the history
Signed-off-by: Gourav <[email protected]>
  • Loading branch information
GauravSaini01 committed Jan 18, 2025
1 parent 5635245 commit 47937a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
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

0 comments on commit 47937a7

Please sign in to comment.