Show errors when validate flag is passed for syntax

This commit is contained in:
Ice3man543 2021-08-31 19:53:53 +05:30
parent 96adaf5257
commit 44700e6c60
2 changed files with 14 additions and 4 deletions

View File

@ -72,6 +72,9 @@ func New(options *types.Options) (*Runner, error) {
}
return nil, nil
}
if options.Validate {
parsers.ShouldValidate = true
}
if err := runner.updateTemplates(); err != nil {
gologger.Warning().Msgf("Could not update templates: %s\n", err)
}

View File

@ -86,11 +86,14 @@ func validateMandatoryInfoFields(info *model.Info) error {
return nil
}
var parsedTemplatesCache *cache.Templates
var fieldErrorRegexp = regexp.MustCompile(`not found in`)
var (
parsedTemplatesCache *cache.Templates
ShouldValidate bool
fieldErrorRegexp = regexp.MustCompile(`not found in`)
)
func init() {
parsedTemplatesCache = cache.New()
stats.NewEntry("syntax-warnings", "Got %d syntax warnings for the loaded templates")
@ -123,7 +126,11 @@ func ParseTemplate(templatePath string) (*templates.Template, error) {
return nil, err
}
stats.Increment("syntax-warnings")
gologger.Warning().Msgf("Syntax warnings for template %s: %s", templatePath, err)
if ShouldValidate {
gologger.Error().Msgf("Syntax warnings for template %s: %s", templatePath, err)
} else {
gologger.Warning().Msgf("Syntax warnings for template %s: %s", templatePath, err)
}
}
parsedTemplatesCache.Store(templatePath, template, nil)
return template, nil