lib/eco/api/common/people/entry_factory.rb in eco-helpers-2.0.47 vs lib/eco/api/common/people/entry_factory.rb in eco-helpers-2.0.48
- old
+ new
@@ -194,10 +194,26 @@
exit(1)
end
ext = File.extname(file)
encoding ||= Eco::API::Common::Session::FileManager.encoding(file)
encoding = (encoding != "utf-8")? "#{encoding}|utf-8": encoding
- content = File.read(file, encoding: encoding)
+ read_with_tolerance(file, encoding: encoding)
+ end
+
+ def read_with_tolerance(file, encoding:)
+ if content = File.read(file, encoding: encoding)
+ tolerance = 5
+ content.scrub do |bytes|
+ replacement = '<' + bytes.unpack('H*')[0] + '>'
+ if tolerance <= 0
+ logger.error("There were more than 5 encoding errors in the file '#{file}'.")
+ return content
+ else
+ logger.error("Encoding problem in file '#{file}': '#{replacement}'.")
+ replacement
+ end
+ end
+ end
end
def fatal(msg)
logger.fatal(msg)
raise msg