From c6849e71d6e1fdf013824349268b2e78e9457a7b Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Thu, 21 Mar 2024 11:10:25 +0100 Subject: [PATCH] Improve ItemStackTag error messages --- jekyll_plugins/ItemStackTag.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/jekyll_plugins/ItemStackTag.rb b/jekyll_plugins/ItemStackTag.rb index d1098c5d..f4c88bcf 100644 --- a/jekyll_plugins/ItemStackTag.rb +++ b/jekyll_plugins/ItemStackTag.rb @@ -79,7 +79,6 @@ def default_mod_data(resource_root, namespace, path) end def fetch_model_data(resource_root_url, namespace, path) - name = "#{namespace}:#{path}" json_url = "#{resource_root_url}/assets/#{namespace}/models/item/#{path}.json" uri = URI.parse(json_url) @@ -92,18 +91,17 @@ def fetch_model_data(resource_root_url, namespace, path) if texture_namespace == namespace "#{resource_root_url}/assets/#{texture_namespace}/textures/#{texture_path}.png" else - raise "Texture in external namespace #{texture_namespace} for #{name}" + raise "Texture in external namespace '#{texture_namespace}'" end else - raise "Unsupported model parent for #{name}: #{model_data["parent"]}" + raise "Unsupported model parent '#{model_data["parent"]}' (only basic 2D item models are supported)" end else - raise "Failed to fetch JSON data for #{name} at #{json_url}: #{response.code} #{response.message}" + raise "Failed to fetch JSON model data at #{json_url}: #{response.code} #{response.message}" end end def fetch_localized_name(resource_root_url, namespace, path) - item_name = "#{namespace}:#{path}" lang_url = "#{resource_root_url}/assets/#{namespace}/lang/en_us.json" lang_data = Ladysnake::Lang.fetch(lang_url) @@ -117,7 +115,7 @@ def fetch_localized_name(resource_root_url, namespace, path) # If neither the item nor the block name was found, raise an error if localized_name.nil? - raise "Localized name not found for #{item_name}" + raise "Localized name not found in #{lang_url}" end localized_name @@ -143,16 +141,13 @@ def default_minecraft_data(item_name) "icon" => icon_url } else - puts "Error: Icon request failed with status code #{icon_response.code} for item #{item_name}" - nil + raise "Wiki Icon request at #{icon_url} failed with status code #{icon_response.code}" end else - puts "Error: Wiki page request failed with status code #{response.code} for item #{item_name}" - nil + raise "Wiki page request at #{url} failed with status code #{response.code}" end rescue StandardError => e - puts "Error: #{e.class}: #{e.message} for item #{item_name}" - nil + raise "#{e.class} while fetching Wiki pages: #{e.message}" end end @@ -167,6 +162,9 @@ def default_data(resource_roots, item_name) nil end end + rescue StandardError => e + puts "Error loading default data for item '#{item_name}': #{e.message}" + nil end end end