{"record":{"id":"c0c34d6c52bf43d1","repo":"we-promise/sure","slug":"class-name-activitiesfetchjob-broadcast-fa","errorCode":null,"errorMessage":"<%= class_name %>ActivitiesFetchJob - Broadcast failed: #{e.message}","messagePattern":"<%= class_name %>ActivitiesFetchJob - Broadcast failed: #(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/generators/provider/family/templates/activities_fetch_job.rb.tt","lineNumber":126,"sourceCode":"        @<%= file_name %>_account,\n        start_date: @start_date,\n        retry_count: @retry_count + 1\n      )\n    end\n\n    def clear_pending_flag\n      @<%= file_name %>_account.update!(activities_fetch_pending: false)\n    end\n\n    def broadcast_updates\n      @<%= file_name %>_account.current_account&.broadcast_sync_complete\n      @<%= file_name %>_account.<%= file_name %>_item&.broadcast_replace_to(\n        @<%= file_name %>_account.<%= file_name %>_item.family,\n        target: \"<%= file_name %>_item_#{@<%= file_name %>_account.<%= file_name %>_item.id}\",\n        partial: \"<%= file_name %>_items/<%= file_name %>_item\"\n      )\n    rescue => e\n      Rails.logger.warn(\"<%= class_name %>ActivitiesFetchJob - Broadcast failed: #{e.message}\")\n    end\nend\n","sourceCodeStart":108,"sourceCodeEnd":129,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/lib/generators/provider/family/templates/activities_fetch_job.rb.tt#L108-L129","documentation":"Generated by the provider generator, this job finishes an activities fetch and then calls broadcast_updates to push Turbo Stream updates: broadcast_sync_complete on the linked account and broadcast_replace_to re-rendering the provider item partial. Any StandardError raised in that UI broadcast path is rescued and downgraded to a warning, so the sync result itself (already persisted) is unaffected — only the live page refresh is lost. Users must reload manually.","triggerScenarios":"current_account (account_provider link) is nil because the provider account was unlinked or the account deleted mid-job; <%= file_name %>_item is nil (item destroyed while the job ran); the target partial path \"<%= file_name %>_items/<%= file_name %>_item\" does not exist because the generator output was renamed; ActionCable/Turbo configuration raising during publish.","commonSituations":"User unlinks an account while a background sync is in flight; developer renames generated files/partial directories after generation; cable adapter misconfigured (e.g. Redis unavailable for ActionCable); staging environments without WebSockets.","solutions":["Read the e.message half of the log line — nil errors point at unlinked records, missing-template errors point at the partial path","Guard the broadcast: return early unless current_account and <%= file_name %>_item are present before broadcasting","Verify the partial app/views/<%= file_name %>_items/_<%= file_name %>_item.html.erb exists after any renaming, both in the generated app and the .tt template","If ActionCable is the cause, check the cable adapter/Redis configuration"],"exampleFix":"# generated job - before\ndef broadcast_updates\n  @account.current_account&.broadcast_sync_complete\n  @account.item&.broadcast_replace_to(...)\nend\n\n# generated job - after\ndef broadcast_updates\n  item = @account.<%= file_name %>_item\n  return unless @account.current_account && item\n\n  @account.current_account.broadcast_sync_complete\n  item.broadcast_replace_to(item.family, target: \"<%= file_name %>_item_#{item.id}\", partial: \"<%= file_name %>_items/<%= file_name %>_item\")\nend","handlingStrategy":"validation","validationCode":"# Only broadcast when the records and partial still exist (generated job)\ndef broadcast_updates\n  item = @account.<%= file_name %>_item\n  linked = @account.current_account\n  partial = \"<%= file_name %>_items/<%= file_name %>_item\"\n  return unless linked && item && lookup_context.exists?(partial, [], true)\n\n  linked.broadcast_sync_complete\n  item.broadcast_replace_to(item.family, target: \"<%= file_name %>_item_#{item.id}\", partial: partial)\nend","typeGuard":null,"tryCatchPattern":"# Keep the broad rescue but log with enough context to act\nrescue => e\n  Rails.logger.warn(\"<%= class_name %>ActivitiesFetchJob - Broadcast failed: #{e.class} #{e.message} account=#{@account&.id} item=#{@account&.<%= file_name %>_item&.id}\")\nend","preventionTips":["Guard nil current_account/item before any broadcast — the dominant cause is records unlinked mid-job","If renaming generated files, update partial path strings in jobs in the same commit","Treat repeated broadcast failures as a signal to check ActionCable adapter health"],"tags":["turbo-rails","broadcast","hotwire","background-jobs","generator-template","nil-safety"],"backgroundTag":"turbo-broadcast-failed","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}