<commit_before>require 'yaml'

module PuppetSyntax
  class Hiera
    def check(filelist)
      raise "Expected an array of files" unless filelist.is_a?(Array)

      errors = []

      filelist.each do |hiera_file|
        begin
          YAML.load_file(hiera_file)
        rescue Exception => error
          errors << error
        end
       end

      errors.map! { |e| e.to_s }

      errors
    end
  end
end
<commit_msg>Let's report the file name when hiera data fails to parse<commit_after>require 'yaml'

module PuppetSyntax
  class Hiera
    def check(filelist)
      raise "Expected an array of files" unless filelist.is_a?(Array)

      errors = []

      filelist.each do |hiera_file|
        begin
          YAML.load_file(hiera_file)
        rescue Exception => error
          errors << "ERROR: Failed to parse #{hiera_file}: #{error}"
        end
       end

      errors.map! { |e| e.to_s }

      errors
    end
  end
end

{'fraction_non_alphanumeric': 0.0818278427205101, 'fraction_numerical': 0.0, 'mean_word_length': 2.0784313725490198, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1750695', 'n_tokens_mistral': 303, 'n_tokens_neox': 294, 'n_words': 87}