{"record":{"id":"a2386d0b9d605cab","repo":"instructure/canvas-lms","slug":"out-of-region-error-report-received","errorCode":null,"errorMessage":"Out of region error report received","messagePattern":"Out of region error report received","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/models/error_report.rb","lineNumber":105,"sourceCode":"        new_backtrace = Array(exception.backtrace)\n        # remove the common lines of the backtrace, and separate it so you can see\n        # the error handling\n        backtrace = (new_backtrace - backtrace) + [\"<Caused>\"] + backtrace\n      end\n      opts[:message] ||= message\n      opts[:backtrace] = backtrace.join(\"\\n\")\n      opts[:exception_message] = message\n      log_error(category, opts)\n    end\n\n    def create_error_report(opts)\n      GuardRail.activate(:primary) do\n        begin\n          report = ErrorReport.new\n          report.assign_data(opts)\n          unless Shard.current.in_current_region?\n            report = nil\n            raise \"Out of region error report received\"\n          end\n\n          report.save!\n          Rails.logger.info(\"Created ErrorReport ID #{report.global_id}\")\n        rescue => e\n          Rails.logger.error(\"Failed creating ErrorReport: #{e.inspect}\")\n          Rails.logger.error(\"Original error: #{opts[:message]}\")\n          Rails.logger.error(\"Original exception: #{opts[:exception_message]}\") if opts[:exception_message]\n          @exception&.backtrace&.each do |line|\n            Rails.logger.error(\"Trace: #{line}\")\n          end\n        end\n        report\n      end\n    end\n  end\n\n  def self.configure_to_ignore(error_classes)","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/error_report.rb#L87-L123","documentation":"ErrorReport creation is refused when the current Shard is not in the current region: writing error reports cross-region would break locality guarantees, so the code sets report = nil and raises 'Out of region error report received' before saving. The rescue logs the failure instead of surfacing it to the user.","triggerScenarios":"log_error/ErrorReport.log_from or Canvas::Errors capture running inside a GuardRail primary block on a shard whose database server lives in a different region than the process (regional failover, cross-region job execution, misrouted request).","commonSituations":"Multi-region Canvas deployments where a job or request executes against a shard in region B while the app is deployed in region A; region failover tests; misconfigured shard/database region mappings.","solutions":["Ensure the job/request runs in the region that owns the shard (correct GuardRail region and job routing)","Fix region/shard configuration so Shard.current is in_current_region? for normal traffic","For out-of-region errors, log to the local logger/external error service instead of creating an ErrorReport row","Verify region setting in config/delayed_jobs and dynamic_settings so processes run in their home region"],"exampleFix":"// before\nErrorReport.log_error(:job, e) # runs on out-of-region shard\n// after\nif Shard.current.in_current_region?\n  ErrorReport.log_error(:job, e)\nelse\n  Rails.logger.error(\"Out of region error: #{e.inspect}\")\nend","handlingStrategy":"try-catch","validationCode":"ErrorReport.log_error(:job, e) if Shard.current.in_current_region?","typeGuard":null,"tryCatchPattern":"begin\n  ErrorReport.log_error(:type, err)\nrescue RuntimeError => e\n  Rails.logger.error(\"no ErrorReport created: #{e.message}\") # already handled internally, mirror the fallback\nend","preventionTips":["Run jobs/requests in the region owning the shard","Keep region/shard configuration in sync across deployments","Add out-of-region logging fallbacks to external error services"],"tags":["ruby","rails","error-reporting","multi-region","sharding"],"backgroundTag":"invalid-config-value","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}