Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 4b37a55c authored by Pierre Neyron's avatar Pierre Neyron 🚴

Properly handle YAML load exceptions (Psych)

parent 1da14960
......@@ -16,20 +16,22 @@ def load_yaml_file_hierarchy(directory)
list_of_yaml_files = Dir['**/*.y*ml', '**/*.y*ml.erb'].sort_by { |x| -x.count('/') }
list_of_yaml_files.each { |filename|
# Load YAML
if /\.y.*ml\.erb$/.match(filename)
# For files with .erb.yaml extensions, process the template before loading the YAML.
file_hash = YAML::load(ERB.new(File.read(filename)).result(binding))
else
file_hash = YAML::load_file(filename)
end
begin
# Load YAML
if /\.y.*ml\.erb$/.match(filename)
# For files with .erb.yaml extensions, process the template before loading the YAML.
file_hash = YAML::load(ERB.new(File.read(filename)).result(binding))
else
file_hash = YAML::load_file(filename)
end
if not file_hash
puts "Error loading '#{filename}'"
next
raise Exception.new("loaded hash is empty")
end
# YAML::Psych raises an exception if the file cannot be loaded.
rescue Exception => e
puts "Error loading '#{filename}', #{e.message}"
end
# Inject the file content into the global_hash, at the right place
path_hierarchy = File.dirname(filename).split('/') # Split the file path (path relative to input/)
path_hierarchy = [] if path_hierarchy == ['.']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment