From b137eed4c40900df247deac012db205f1332e1f2 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 20 Jun 2024 14:08:40 -0700 Subject: [PATCH] Oops, handle date parsing errors in Dyeworks logic Huh, I thought I'd tried some invalid dates and they gave me *surprising* output instead of raising an error. Well, maybe it can do both, depending on exactly the nature of the unexpected input? In any case, I found that a bad month name like "UwU" raised an error. So, let's catch it if so! --- app/models/item/dyeworks.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/item/dyeworks.rb b/app/models/item/dyeworks.rb index 279a5f3f..d14353b7 100644 --- a/app/models/item/dyeworks.rb +++ b/app/models/item/dyeworks.rb @@ -80,9 +80,15 @@ class Item # NOTE: This could return strange results if the Owls date contains # something surprising! But the heuristic nature helps with e.g. # flexibility if they abbreviate months, so let's lean into `Date.parse`. - match => {month:, day:} - date = Date.parse("#{month} #{day}, #{Date.today.year}") - date += 1.year if date < Date.today - 3.months + begin + match => {month:, day:} + date = Date.parse("#{month} #{day}, #{Date.today.year}") + date += 1.year if date < Date.today - 3.months + rescue Date::Error + Rails.logger.warn "Could not parse Dyeworks final date: " + + "#{nc_trade_value.value_text.inspect}" + return nil + end date end