{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/26776","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/26776/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/26776/comments","events_url":"https://api.github.com/repos/rails/rails/issues/26776/events","html_url":"https://github.com/rails/rails/issues/26776","id":182659933,"number":26776,"title":"rescue_from StandardError does not allow rescuing exceptions that are translated by the ConnectionAdapters","user":{"login":"dukejones","id":104690,"avatar_url":"https://avatars.githubusercontent.com/u/104690?v=3","gravatar_id":"","url":"https://api.github.com/users/dukejones","html_url":"https://github.com/dukejones","followers_url":"https://api.github.com/users/dukejones/followers","following_url":"https://api.github.com/users/dukejones/following{/other_user}","gists_url":"https://api.github.com/users/dukejones/gists{/gist_id}","starred_url":"https://api.github.com/users/dukejones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dukejones/subscriptions","organizations_url":"https://api.github.com/users/dukejones/orgs","repos_url":"https://api.github.com/users/dukejones/repos","events_url":"https://api.github.com/users/dukejones/events{/privacy}","received_events_url":"https://api.github.com/users/dukejones/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-12T23:34:02Z","updated_at":"2016-10-12T23:58:14Z","closed_at":null,"body":"### Steps to reproduce\r\n\r\nCreate a unique index in your schema.\r\n\r\nPlace these lines in your ApplicationController:\r\n```ruby\r\n  rescue_from StandardError do |e|\r\n    render json: {error: 'Everything else'}, status: 500\r\n  end\r\n\r\n  rescue_from ActiveRecord::RecordNotUnique do |e|\r\n    render json: {error: 'Record not unique!'}, status: 500\r\n  end\r\n```\r\n\r\nThen with a controller test, attempt to create a record that violates the uniqueness.\r\n\r\n### Expected behavior\r\n```ruby\r\n  json  # =>  {error: 'Record not unique!'}\r\n```\r\n\r\n### Actual behavior\r\n```ruby\r\n  json  # =>  {error: 'Everything else'}\r\n```\r\n\r\n### System configuration\r\n**Rails version**:\r\nTested with 4.2.  This should still be an issue from looking at code changes between 4.2 and master.\r\n**Ruby version**:\r\n2.1.2p95\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/253373331","html_url":"https://github.com/rails/rails/issues/26776#issuecomment-253373331","issue_url":"https://api.github.com/repos/rails/rails/issues/26776","id":253373331,"user":{"login":"dukejones","id":104690,"avatar_url":"https://avatars.githubusercontent.com/u/104690?v=3","gravatar_id":"","url":"https://api.github.com/users/dukejones","html_url":"https://github.com/dukejones","followers_url":"https://api.github.com/users/dukejones/followers","following_url":"https://api.github.com/users/dukejones/following{/other_user}","gists_url":"https://api.github.com/users/dukejones/gists{/gist_id}","starred_url":"https://api.github.com/users/dukejones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dukejones/subscriptions","organizations_url":"https://api.github.com/users/dukejones/orgs","repos_url":"https://api.github.com/users/dukejones/repos","events_url":"https://api.github.com/users/dukejones/events{/privacy}","received_events_url":"https://api.github.com/users/dukejones/received_events","type":"User","site_admin":false},"created_at":"2016-10-12T23:58:14Z","updated_at":"2016-10-12T23:58:14Z","body":"You're right.\r\n```ruby\r\nbegin\r\n  require \"bundler/inline\"\r\nrescue LoadError => e\r\n  $stderr.puts \"Bundler version 1.10 or later is required. Please update your Bundler\"\r\n  raise e\r\nend\r\n\r\ngemfile(true) do\r\n  source \"https://rubygems.org\"\r\n  gem \"rails\", github: \"rails/rails\"\r\n  gem \"sqlite3\"\r\n  gem \"pry\"\r\nend\r\n\r\nrequire \"active_record\"\r\nrequire \"action_controller/railtie\"\r\nrequire \"minitest/autorun\"\r\nrequire \"logger\"\r\nrequire \"rack/test\"\r\n\r\n# This connection will do for database-independent bug reports.\r\nActiveRecord::Base.establish_connection(adapter: \"sqlite3\", database: \":memory:\")\r\nActiveRecord::Base.logger = Logger.new(STDOUT)\r\n\r\nActiveRecord::Schema.define do\r\n  create_table :posts, force: true do |t|\r\n    t.string :name\r\n  end\r\n  add_index :posts, :name, unique: true\r\nend\r\n\r\nclass Post < ActiveRecord::Base\r\n  has_many :comments\r\nend\r\n\r\nclass TestApp < Rails::Application\r\n  config.root = File.dirname(__FILE__)\r\n  secrets.secret_token    = \"secret_token\"\r\n  secrets.secret_key_base = \"secret_key_base\"\r\n\r\n  config.logger = Logger.new($stdout)\r\n  Rails.logger  = config.logger\r\n\r\n  routes.draw do\r\n    post \"/\" => \"test#create\"\r\n  end\r\nend\r\n\r\nclass TestController < ActionController::Base\r\n  include Rails.application.routes.url_helpers\r\n\r\n  rescue_from StandardError do |exception|\r\n    render plain: 'Standard Error'\r\n  end\r\n\r\n  rescue_from ActiveRecord::RecordNotUnique do |exception|\r\n    render plain: 'This record is not unique!'\r\n  end\r\n\r\n  def create\r\n    Post.create(name: params[:name])\r\n    render json: {message: 'created'}\r\n  end\r\nend\r\n\r\nclass BugTest < Minitest::Test\r\n  include Rack::Test::Methods\r\n\r\n  def test_returns_success\r\n    Post.create!(name: 'duke')\r\n    post \"/\", { name: 'duke' }\r\n\r\n    assert_equal \"This record is not unique!\", last_response.body\r\n  end\r\n\r\n  private\r\n    def app\r\n      Rails.application\r\n    end\r\nend\r\nclass BugTest < Minitest::Test\r\n  def test_association_stuff\r\n  end\r\nend\r\n```\r\n\r\nThis works on rails master."}}
{"actor":{"display_login":"dukejones"}}