@@ -59,36 +59,36 @@ async function parse (filePath) {
5959 content = JSON . stringify ( filePath ) ;
6060 } else {
6161 console . error ( `Could not find a valid asyncapi definition: ${ filePath } ` ) ;
62- return ;
62+ throw new Error ( `Could not find a valid asyncapi definition: ${ filePath } ` ) ;
6363 }
6464 } catch ( e ) {
6565 console . error ( 'Can not load the content of the AsyncAPI specification file' ) ;
6666 console . error ( e ) ;
67- return ;
67+ throw e ;
6868 }
6969
7070 try {
7171 parsedContent = parseContent ( content ) ;
7272 } catch ( e ) {
7373 console . error ( 'Can not parse the content of the AsyncAPI specification file' ) ;
7474 console . error ( e ) ;
75- return ;
75+ throw e ;
7676 }
7777
7878 try {
7979 dereferencedJSON = await dereference ( parsedContent ) ;
8080 } catch ( e ) {
8181 console . error ( 'Can not dereference the JSON obtained from the content of the AsyncAPI specification file' ) ;
8282 console . error ( e ) ;
83- return ;
83+ throw e ;
8484 }
8585
8686 try {
8787 bundledJSON = await bundle ( dereferencedJSON ) ;
8888 } catch ( e ) {
8989 console . error ( 'Can not bundle the JSON obtained from the content of the AsyncAPI specification file' ) ;
9090 console . error ( e ) ;
91- return ;
91+ throw e ;
9292 }
9393
9494 try {
@@ -97,24 +97,32 @@ async function parse (filePath) {
9797 } catch ( e ) {
9898 console . error ( 'Invalid JSON obtained from the content of the AsyncAPI specification file' ) ;
9999 console . error ( e ) ;
100- return ;
100+ throw e ;
101101 }
102102
103103 return JSON . parse ( JSON . stringify ( parsed ) ) ;
104104} ;
105105
106106async function parseText ( content ) {
107- const parsedContent = parseContent ( content ) ;
108- if ( typeof parsedContent !== 'object' || parsedContent === null ) {
109- throw new Error ( 'Invalid YAML content.' ) ;
110- }
111- const dereferencedJSON = await dereference ( parsedContent ) ;
112- const bundledJSON = await bundle ( dereferencedJSON ) ;
113- const asyncAPIschema = require ( 'asyncapi' ) [ bundledJSON . asyncapi ] ;
107+ let parsedStringified ;
114108
115- const parsed = await validate ( bundledJSON , asyncAPIschema ) ;
109+ try {
110+ const parsedContent = parseContent ( content ) ;
111+ if ( typeof parsedContent !== 'object' || parsedContent === null ) {
112+ throw new Error ( 'Invalid YAML content.' ) ;
113+ }
114+ const dereferencedJSON = await dereference ( parsedContent ) ;
115+ const bundledJSON = await bundle ( dereferencedJSON ) ;
116+ const asyncAPIschema = require ( 'asyncapi' ) [ bundledJSON . asyncapi ] ;
116117
117- return JSON . parse ( JSON . stringify ( parsed ) ) ;
118+ const parsed = await validate ( bundledJSON , asyncAPIschema ) ;
119+
120+ parsedStringified = JSON . parse ( JSON . stringify ( parsed ) ) ;
121+ } catch ( e ) {
122+ throw e ;
123+ }
124+
125+ return parsedStringified
118126} ;
119127
120128module . exports = parse ;
0 commit comments