Skip to content

Commit

Permalink
Improve ItemStackTag error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Mar 21, 2024
1 parent 8afc0fe commit c6849e7
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions jekyll_plugins/ItemStackTag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit c6849e7

Please sign in to comment.