Guard nil datapoint in RunSimulateDataPoint rescue logging#850
Closed
SAY-5 wants to merge 1 commit into
Closed
Conversation
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Contributor
There was a problem hiding this comment.
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.warnwhendis 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 |
Contributor
|
Closing — we'll address this in-house via #846. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ResqueJobs::RunSimulateDataPoint.performbindsd = DataPoint.find(data_point_id)on its first line. When that lookup raises (the datapoint was deleted, DB blip, etc.),dis still nil when eitherrescueblock runs, and both calld.add_to_rails_log(...). That raisesNoMethodError: 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 theSignalException/DirtyExitrescue.Fixes #848.
Change
Guard
din both rescue paths: log throughadd_to_rails_logwhen the datapoint is present, otherwise fall back toRails.logger.warnso the root cause is still recorded. This mirrors the nil-safe rescue logging already added to the siblingInitializeAnalysisjob (#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 beforeperformruns 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 isruby -cclean and confined to the two rescue branches.