From 9d8f0353609affee774546888874ac18e356fb3a Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 16 Apr 2024 10:03:36 -0700 Subject: [PATCH] Oops, stop crashing when modeling "pets" that start with `@` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ahh, we recently added a step to pet loading that sends a metadata request to `PetService.getPet`, which is now (in a sense, correctly!) raising a `PetNotFound` error when we try modeling with a "pet" that starts with `@` (a trick we use in situations where we can get an image hash for a modeling situation, but not an irl pet itself). In this change, we make it no longer a crashing issue if the pet metadata request fails: it's not a big deal to have a `PetType` have no image hash or not have it be up-to-date! In the next change, I'll also add an optimization to skip fetching it altogether in this caseā€”but I wanted to see this work first, because the more general resilience is more important imo! --- app/models/pet.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/pet.rb b/app/models/pet.rb index ee222cef..0557fea4 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -35,7 +35,11 @@ class Pet < ApplicationRecord color_id: pet_data[:color_id].to_i ) - new_image_hash = Pet.fetch_image_hash(self.name) + begin + new_image_hash = Pet.fetch_image_hash(self.name) + rescue => error + Rails.logger.warn "Failed to load image hash: #{error.full_message}" + end self.pet_type.image_hash = new_image_hash if new_image_hash.present? # With an alt style, `body_id` in the biology data refers to the body ID of