Skip to content

Commit

Permalink
add better error
Browse files Browse the repository at this point in the history
  • Loading branch information
KhudaDad414 committed Oct 20, 2023
1 parent 2c8e4b1 commit 35aef4b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/asyncapiFile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { readFile } from 'fs/promises'
import { AsyncAPIDocumentInterface as AsyncAPIDocument, Parser, toAsyncAPIDocument} from '@asyncapi/parser'
import { getConfigs } from './configs.js'
import { logError } from './logger.js'

export async function getParsedAsyncAPI(): Promise<AsyncAPIDocument> {
const { ASYNCAPI_FILE_PATH } = getConfigs()
const asyncapiFileContent = await readFile(ASYNCAPI_FILE_PATH, 'utf-8')

Check warning on line 8 in src/lib/asyncapiFile.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Found readFile from package "fs/promises" with non literal argument at index 0

Check warning on line 8 in src/lib/asyncapiFile.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - macos-latest

Found readFile from package "fs/promises" with non literal argument at index 0
const parser = new Parser()
const {document} = await parser.parse(asyncapiFileContent)
const { document, diagnostics } = await parser.parse(asyncapiFileContent)
if (!document) {
const errorMessage = 'Failed to parse the AsyncAPI document.'
logError(new Error(errorMessage))
console.error(diagnostics)
process.exit(1)
}
return toAsyncAPIDocument(document)
}

Expand Down

0 comments on commit 35aef4b

Please sign in to comment.