From 388614732b34a5e1fbc7c60bb9082b4e8ef05df5 Mon Sep 17 00:00:00 2001 From: shaheenery Date: Tue, 25 Nov 2008 20:14:46 -0500 Subject: [PATCH] added a new exception to catch empty or malformed translation source files --- .../vendor/i18n-0.0.1/i18n/backend/simple.rb | 7 ++++++- .../vendor/i18n-0.0.1/i18n/exceptions.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb index bdda55d..2a53ac7 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb @@ -172,10 +172,15 @@ module I18n # #load_yml depending on the file extension and directly merges the # data to the existing translations. Raises I18n::UnknownFileType # for all other file extensions. + # + # If file is empty or malformed we raise a I18n::MalformedSourceFile + # and pass the file name to assist with debugging + def load_file(filename) type = File.extname(filename).tr('.', '').downcase raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}") - data = send :"load_#{type}", filename # TODO raise a meaningful exception if this does not yield a Hash + data = send :"load_#{type}", filename + raise MalformedSourceFile.new(filename) unless data.is_a?(Hash) data.each { |locale, d| merge_translations(locale, d) } end diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb index 0f3eff1..fd84a5e 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb @@ -50,4 +50,13 @@ module I18n super "can not load translations from #{filename}, the file type #{type} is not known" end end + + class MalformedSourceFile < ArgumentError + attr_reader :filename + def initialize(filename) + @filename = filename + super "cannot load data from the file #{filename}, must be properly formatted and not blank" + end + end + end \ No newline at end of file -- 1.6.0.1