From b9560973986422e2bde95816e10b416130893449 Mon Sep 17 00:00:00 2001 From: Aayush Date: Sat, 16 Sep 2023 11:18:34 +0530 Subject: [PATCH] resolve test case failure --- src/errors/specification-file.ts | 26 +++++++++++++------------- src/models/SpecificationFile.ts | 9 +++++---- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/errors/specification-file.ts b/src/errors/specification-file.ts index 2f18eb04f74..9df74db9218 100644 --- a/src/errors/specification-file.ts +++ b/src/errors/specification-file.ts @@ -35,19 +35,19 @@ export class ErrorLoadingSpec extends Error { if (from === 'file') { this.name = 'error loading AsyncAPI document from file'; this.message = `${param} file does not exist.`; - } else - if (from === 'url') { - this.name = 'error loading AsyncAPI document from url'; - this.message = `Failed to download ${param}.`; - } else - if (from === 'context') { - this.name = 'error loading AsyncAPI document from context'; - this.message = `${param} context name does not exist.`; - } else - if (from === 'invalid file') { - this.name = 'Invalid AsyncAPI file type'; - this.message = 'cli only supports yml ,yaml ,json extension'; - } + } + if (from === 'url') { + this.name = 'error loading AsyncAPI document from url'; + this.message = `Failed to download ${param}.`; + } + if (from === 'context') { + this.name = 'error loading AsyncAPI document from context'; + this.message = `${param} context name does not exist.`; + } + if (from === 'invalid file') { + this.name = 'Invalid AsyncAPI file type'; + this.message = 'cli only supports yml ,yaml ,json extension'; + } if (!from) { this.name = 'error locating AsyncAPI document'; diff --git a/src/models/SpecificationFile.ts b/src/models/SpecificationFile.ts index 8d95c26d611..4d4fe917bf0 100644 --- a/src/models/SpecificationFile.ts +++ b/src/models/SpecificationFile.ts @@ -182,6 +182,10 @@ export async function isURL(urlpath: string): Promise { export async function fileExists(name: string): Promise { try { + if ((await lstat(name)).isFile()) { + return true; + } + const extension = name.split('.')[1]; const allowedExtenstion=['yml','yaml','json']; @@ -189,10 +193,7 @@ export async function fileExists(name: string): Promise { if (!allowedExtenstion.includes(extension)) { throw new ErrorLoadingSpec('invalid file',name); } - - if ((await lstat(name)).isFile()) { - return true; - } + throw new ErrorLoadingSpec('file', name); } catch (e) { throw new ErrorLoadingSpec('file', name);