From 4c158934d0f650a8bc2fa9f35645b31d3502454c Mon Sep 17 00:00:00 2001 From: Josh Pigford Date: Mon, 3 Feb 2025 19:57:58 -0600 Subject: [PATCH] Improve Security Price Loading with Robust Error Handling - Add error handling for individual security price loading - Log detailed error information for problematic securities - Prevent single security errors from halting entire price loading process - Enhance logging with more specific security identification details --- app/models/account/holding_calculator.rb | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/app/models/account/holding_calculator.rb b/app/models/account/holding_calculator.rb index 80accb5c..b82ad47a 100644 --- a/app/models/account/holding_calculator.rb +++ b/app/models/account/holding_calculator.rb @@ -121,20 +121,27 @@ class Account::HoldingCalculator Rails.logger.info "[HoldingCalculator] Preloading #{securities.size} securities for account #{account.id}" securities.each do |security| - Rails.logger.info "[HoldingCalculator] Loading prices for security #{security.id} (#{security.symbol})" + begin + Rails.logger.info "[HoldingCalculator] Loading security: ID=#{security.id} Ticker=#{security.ticker}" - prices = Security::Price.find_prices( - security: security, - start_date: portfolio_start_date, - end_date: Date.current - ) + prices = Security::Price.find_prices( + security: security, + start_date: portfolio_start_date, + end_date: Date.current + ) - Rails.logger.info "[HoldingCalculator] Found #{prices.size} prices for security #{security.id}" + Rails.logger.info "[HoldingCalculator] Found #{prices.size} prices for security #{security.id}" - @securities_cache[security.id] = { - security: security, - prices: prices - } + @securities_cache[security.id] = { + security: security, + prices: prices + } + rescue => e + Rails.logger.error "[HoldingCalculator] Error processing security #{security.id}: #{e.message}" + Rails.logger.error "[HoldingCalculator] Security details: #{security.attributes}" + Rails.logger.error e.backtrace.join("\n") + next # Skip this security and continue with others + end end end