Skip to content

Fix nil error in Analytics.last_month#52

Merged
jvendetti merged 3 commits intomasterfrom
fix/analytics-nil-safe-lookup
Apr 15, 2026
Merged

Fix nil error in Analytics.last_month#52
jvendetti merged 3 commits intomasterfrom
fix/analytics-nil-safe-lookup

Conversation

@jvendetti
Copy link
Copy Markdown
Member

@jvendetti jvendetti commented Apr 15, 2026

Summary

  • Replace unsafe chained hash access (analytics[ont][:"#{year_num}"][:"#{month_num}"]) with Hash#dig to prevent NoMethodError when analytics[ont] is nil
  • Default to 0 views and log a debug-level message when analytics data is missing for an ontology
  • Add class-level LOGGER constant for structured logging
  • Fix some RuboCop warnings

Test plan

  • Verify Analytics.last_month returns results without errors when all ontology data is present
  • Verify no exception is raised when analytics[ont] is nil for some ontologies
  • Confirm debug log message appears when analytics data is missing

🤖 Generated with Claude Code

jvendetti and others added 2 commits April 14, 2026 18:01
Use Hash#dig for nil-safe nested hash access instead of chained bracket
lookups, which raised NoMethodError when analytics[ont] was nil. Defaults
to 0 views and logs a debug message when data is missing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 18.18182% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.48%. Comparing base (67f3b05) to head (b854d0b).

Files with missing lines Patch % Lines
lib/ontologies_api_client/analytics.rb 18.18% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #52      +/-   ##
==========================================
- Coverage   67.21%   66.48%   -0.73%     
==========================================
  Files          29       29              
  Lines         915      919       +4     
  Branches      172      174       +2     
==========================================
- Hits          615      611       -4     
- Misses        300      308       +8     
Flag Coverage Δ
3.2 66.48% <18.18%> (-0.73%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jvendetti jvendetti self-assigned this Apr 15, 2026
@jvendetti jvendetti merged commit 9514e72 into master Apr 15, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants