@@ -21,7 +21,6 @@ const fs = require('fs').promises;
2121const path = require ( 'path' ) ;
2222const yaml = require ( 'js-yaml' ) ;
2323
24- const Template = require ( './lib/template' ) . Template ;
2524const FsTemplateProvider = require ( './lib/template_provider' ) . FsTemplateProvider ;
2625const guiUtils = require ( './lib/gui_utils' ) ;
2726
@@ -82,11 +81,17 @@ const loadTemplate = (templatePath) => {
8281 const provider = new FsTemplateProvider ( tsDir , [ tsName ] ) ;
8382 return provider . fetch ( `${ tsName } /${ tmplName } ` )
8483 . catch ( ( e ) => {
85- const validationErrors = Template . getValidationErrors ( ) ;
86- if ( validationErrors !== 'null' ) {
87- logger . error ( validationErrors ) ;
84+ const validationErrors = e . validationErrors ;
85+ const errMsg = ( validationErrors ) ? 'template failed validation' : e . message ;
86+ logger . error ( `failed to load template: ${ errMsg } ` ) ;
87+ if ( validationErrors ) {
88+ if ( logger . isJSON ) {
89+ logger . output . validationErrors = validationErrors ;
90+ } else {
91+ logger . error ( 'validation errors:' ) ;
92+ logger . error ( validationErrors ) ;
93+ }
8894 }
89- logger . error ( `failed to load template\n${ e . stack } ` ) ;
9095 process . exit ( 1 ) ;
9196 } ) ;
9297} ;
@@ -187,9 +192,22 @@ const validateTemplateSet = (tsPath) => {
187192 templateList . map (
188193 tmpl => provider . fetch ( tmpl )
189194 . catch ( ( e ) => {
190- logger . error (
191- `Template "${ tmpl } " failed validation:\n${ e . stack } \n`
192- ) ;
195+ const validationErrors = e . validationErrors ;
196+ const errMsg = `Template ${ tmpl } failed validation: ${ e . message } ` ;
197+ if ( validationErrors ) {
198+ if ( logger . isJSON ) {
199+ if ( ! logger . output . errors ) {
200+ logger . output . errors = [ ] ;
201+ }
202+ logger . output . errors . push ( {
203+ message : errMsg ,
204+ validationErrors
205+ } ) ;
206+ } else {
207+ logger . error ( errMsg ) ;
208+ logger . error ( validationErrors ) ;
209+ }
210+ }
193211 errorFound = true ;
194212 } )
195213
0 commit comments