{"record":{"id":"8296a6dc4c0e5189","repo":"we-promise/sure","slug":"record-not-found-8296a6","errorCode":"record_not_found","errorMessage":"The requested resource was not found","messagePattern":"The requested resource was not found","errorType":"http","errorClass":"ActiveRecord::RecordNotFound","httpStatus":404,"severity":"error","filePath":"app/controllers/api/v1/family_exports_controller.rb","lineNumber":85,"sourceCode":"      }, status: :conflict\n      return\n    end\n\n    redirect_to rails_blob_url(@family_export.export_file, disposition: \"attachment\"), allow_other_host: true\n  rescue StandardError => e\n    Rails.logger.error \"FamilyExportsController#download error: #{e.message}\"\n    Rails.logger.error e.backtrace.join(\"\\n\")\n\n    render json: {\n      error: \"internal_server_error\",\n      message: \"An unexpected error occurred\"\n    }, status: :internal_server_error\n  end\n\n  private\n\n    def set_family_export\n      raise ActiveRecord::RecordNotFound unless valid_uuid?(params[:id])\n\n      @family_export = current_resource_owner.family.family_exports.find(params[:id])\n    end\n\n    def ensure_read_scope\n      authorize_scope!(:read)\n    end\n\n    def ensure_write_scope\n      authorize_scope!(:write)\n    end\n\n    def ensure_admin\n      return if current_resource_owner.admin?\n\n      render json: {\n        error: \"forbidden\",\n        message: \"Family exports require a family admin\"","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/controllers/api/v1/family_exports_controller.rb#L67-L103","documentation":"Raised by the set_family_export before_action in Api::V1::FamilyExportsController (app/controllers/api/v1/family_exports_controller.rb:85). It fires when params[:id] is not a valid UUID (the guard raises ActiveRecord::RecordNotFound immediately) or when current_resource_owner.family.family_exports.find(:id) matches no row, i.e. the export exists but belongs to another family. The API base maps RecordNotFound to a 404 with error code record_not_found.","triggerScenarios":"GET /api/v1/family_exports/:id (or the download route) with a non-UUID id such as 'latest' or '1'; a well-formed UUID created under a different family; an export deleted (or cleaned up by a retention job) between listing and download; an X-Api-Key whose owner's family simply has no such export.","commonSituations":"Reusing an export id captured in another environment (staging id against production); expired/purged export files; a truncated or URL-mangled UUID (missing dashes, half-copied); rotating API keys between families.","solutions":["Re-list exports with GET /api/v1/family_exports and use an id from the response","Validate the id is a UUID (8-4-4-4-12 hex) before hitting /:id","Confirm the X-Api-Key belongs to the family that created the export","Treat 404 record_not_found as 'gone': re-create the export instead of retrying the download"],"exampleFix":"# before\nGET /api/v1/family_exports/0e8d1ceb-5b6d\n# after\nGET /api/v1/family_exports\nGET /api/v1/family_exports/0e8d1ceb-5b6d-4a85-9f2e-74f3b1a2c9d4","handlingStrategy":"try-catch","validationCode":"UUID_RE = /\\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\z/i\nUUID_RE.match?(export_id) or raise ArgumentError, 'family_export id must be a UUID'","typeGuard":null,"tryCatchPattern":"begin\n  resp = client.get(\"/api/v1/family_exports/#{id}\")\nrescue Faraday::ResourceNotFound\n  # 404 record_not_found: export gone or other family — re-list or re-create\nend","preventionTips":["Always source :id from GET /api/v1/family_exports","Never hardcode export ids across environments","Store the export id at creation time in the same system that downloads it"],"tags":["rails","activerecord","record-not-found","http-404","uuid","api"],"backgroundTag":"record-not-found","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}