Skip to content

Guard nil datapoint in RunSimulateDataPoint rescue logging#850

Closed
SAY-5 wants to merge 1 commit into
NatLabRockies:developfrom
SAY-5:fix-nil-datapoint-error-log
Closed

Guard nil datapoint in RunSimulateDataPoint rescue logging#850
SAY-5 wants to merge 1 commit into
NatLabRockies:developfrom
SAY-5:fix-nil-datapoint-error-log

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 20, 2026

Copy link
Copy Markdown

Problem

ResqueJobs::RunSimulateDataPoint.perform binds d = DataPoint.find(data_point_id) on its first line. When that lookup raises (the datapoint was deleted, DB blip, etc.), d is still nil when either rescue block runs, and both call d.add_to_rails_log(...). That raises NoMethodError: undefined method 'add_to_rails_log' for nil, which masks the original error and turns a would-be retryable failure into a permanent failed job. Same nil hazard in the SignalException/DirtyExit rescue.

Fixes #848.

Change

Guard d in both rescue paths: log through add_to_rails_log when the datapoint is present, otherwise fall back to Rails.logger.warn so the root cause is still recorded. This mirrors the nil-safe rescue logging already added to the sibling InitializeAnalysis job (#841). No behavior change on the happy path.

Test

Added a regression case to resque_run_simulate_data_point_hardening_spec.rb: destroying the datapoint before perform runs and asserting it no longer raises. The full spec needs the docker Rails/Postgres/Redis stack, so I could not run the suite locally; the change is ruby -c clean and confined to the two rescue branches.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens ResqueJobs::RunSimulateDataPoint.perform error handling so that failures during DataPoint.find don’t trigger a secondary NoMethodError in the rescue logger, preserving the original failure context.

Changes:

  • Guard rescue-path logging so it falls back to Rails.logger.warn when d is nil.
  • Add a regression spec covering the “datapoint deleted before perform” scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
server/app/jobs/resque_jobs/run_simulate_data_point.rb Adds nil-safe logging in both rescue paths to avoid crashing while handling an exception.
server/spec/models/resque_run_simulate_data_point_hardening_spec.rb Adds a regression example for the nil-datapoint rescue path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +57 to +61
msg = "Worker Caught Exception: #{e.inspect}"#: Re-enqueueing DataPoint ID #{data_point_id}")
d.nil? ? Rails.logger.warn(msg) : d.add_to_rails_log(msg)
#Resque.enqueue_to(:requeued, self, data_point_id, options)
#puts "DataPoint #{data_point_id} re-enqueued."
puts "Worker Caught Exception: #{e.inspect}"
puts msg
Comment on lines +63 to +67
msg = "Worker Caught Unhandled Exception: #{e.message}"#: Re-enqueueing DataPoint ID #{data_point_id}")
d.nil? ? Rails.logger.warn(msg) : d.add_to_rails_log(msg)
#Resque.enqueue_to(:requeued, self, data_point_id, options)
#puts "Unhandled exception, re-enqueued DataPoint."
puts "Worker Caught Unhandled Exception: #{e.message}"
puts msg
Comment on lines +119 to +123
missing_id = data_point.id
data_point.destroy!

expect { described_class.perform(missing_id) }.not_to raise_error
end
@brianlball

Copy link
Copy Markdown
Contributor

Closing — we'll address this in-house via #846. Thanks.

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.

Fix nil crash in RunSimulateDataPoint error logging

3 participants