From 7c98c250dee5a0c02e1c2e1dbce9af3e53095e91 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 30 Oct 2023 16:57:33 +1300 Subject: [PATCH 1/3] feat: report parse failure reasons For [](https://github.com/asyncapi/generator/issues/1051) I opted for the more basic logging style - I don't know enough about the diagnostics objects to be sure that they'll always contain the same fields, so erred on the side of caution rather than trying to access fields within fields that aren't guaranteed to exist (as well as including all available information, regardless of what is provided). --- lib/generator.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/generator.js b/lib/generator.js index 0203f3a64..e838881c4 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -353,6 +353,9 @@ class Generator { if (!document) { const err = new Error('Input is not a correct AsyncAPI document so it cannot be processed.'); err.diagnostics = diagnostics; + for (const diag of diagnostics) { + console.error('Diagnotic err:', diag); + } throw err; } else { this.asyncapi = document; From cd54999128d87b061462926bda5c3c76498f9c37 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 20 Nov 2023 18:38:05 +1300 Subject: [PATCH 2/3] use more-verbose error reporting --- lib/generator.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/generator.js b/lib/generator.js index e838881c4..995852399 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -354,7 +354,11 @@ class Generator { const err = new Error('Input is not a correct AsyncAPI document so it cannot be processed.'); err.diagnostics = diagnostics; for (const diag of diagnostics) { - console.error('Diagnotic err:', diag); + console.error( + `Diagnostic err: ${diag['message']} in path ${JSON.stringify(diag['path'])} starting `+ + `L${diag['range']['start']['line']} C${diag['range']['start']['character']}, ending `+ + `L${diag['range']['end']['line']} C${diag['range']['end']['character']}` + ); } throw err; } else { From c675697164cf1f05c126b2e8e5646aacc4179178 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 20 Nov 2023 18:58:35 +1300 Subject: [PATCH 3/3] bump line numbers by 1 to follow line numbering conventions --- lib/generator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index 995852399..7781c25cc 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -356,8 +356,8 @@ class Generator { for (const diag of diagnostics) { console.error( `Diagnostic err: ${diag['message']} in path ${JSON.stringify(diag['path'])} starting `+ - `L${diag['range']['start']['line']} C${diag['range']['start']['character']}, ending `+ - `L${diag['range']['end']['line']} C${diag['range']['end']['character']}` + `L${diag['range']['start']['line'] + 1} C${diag['range']['start']['character']}, ending `+ + `L${diag['range']['end']['line'] + 1} C${diag['range']['end']['character']}` ); } throw err;