{"record":{"id":"2c6d72a8e792b7de","repo":"teamcapybara/capybara","slug":"your-application-server-raised-an-error-it-has-b","errorCode":null,"errorMessage":"Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true","messagePattern":"Your application server raised an error - It has been raised in your test code because Capybara\\.raise_server_errors == true","errorType":"exception","errorClass":"CapybaraError","httpStatus":null,"severity":"error","filePath":"lib/capybara/session.rb","lineNumber":164,"sourceCode":"    #\n    def quit\n      @driver.quit if @driver.respond_to? :quit\n      @document = @driver = nil\n      @touched = false\n      @server&.reset_error!\n    end\n\n    ##\n    #\n    # Raise errors encountered in the server.\n    #\n    def raise_server_error!\n      return unless @server&.error\n\n      # Force an explanation for the error being raised as the exception cause\n      begin\n        if config.raise_server_errors\n          raise CapybaraError, 'Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true'\n        end\n      rescue CapybaraError => capy_error # rubocop:disable Naming/RescuedExceptionsVariableName\n        raise @server.error, cause: capy_error\n      ensure\n        @server.reset_error!\n      end\n    end\n\n    ##\n    #\n    # Returns a hash of response headers. Not supported by all drivers (e.g. Selenium).\n    #\n    # @return [Hash<String, String>] A hash of response headers.\n    #\n    def response_headers\n      driver.response_headers\n    end\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/session.rb#L146-L182","documentation":"When the application under test raises while serving a request, Capybara's test server stores the exception; on the next driver interaction raise_server_error! re-raises it in the test thread. This CapybaraError is attached as the exception cause to explain that Capybara.raise_server_errors == true promoted the app error into the test run.","triggerScenarios":"A controller/model exception during visit/click (app returns 500) followed by any further Capybara call; exceptions of classes listed in Capybara.server_errors (default StandardError) raised by middleware or the app itself.","commonSituations":"Genuine app bugs surfaced by feature specs; environment-specific failures (missing env var, migration mismatch) only raising in test env; specs that intentionally visit broken endpoints; flaky uniqueness/validation errors under parallel tests.","solutions":["Inspect the cause: rescue => e; puts e.cause.full_message - the real app exception and backtrace are there; then fix the app code","Reproduce outside Capybara (request spec, curl against the booted server port, test.log) if the cause is unclear","When visiting intentionally-broken endpoints, narrow Capybara.server_errors to specific classes or temporarily set Capybara.raise_server_errors = false in an around-hook - debug only, since it hides real failures","Check the app's own log for the original stack trace"],"exampleFix":"# before\nit 'shows checkout' do\n  visit '/checkout' # raises wrapped CapybaraError, real cause buried\nend\n\n# after (surface the real app error while debugging)\nit 'shows checkout' do\n  visit '/checkout'\nrescue Capybara::CapybaraError => e\n  raise e.cause if e.cause # re-raise the actual app exception\n  raise\nend","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  visit '/checkout'\n  click_button 'Pay'\nrescue Capybara::CapybaraError => e\n  # e.cause holds the real exception raised by your app\n  AppErrorReporter.notify(e.cause) if e.cause\n  raise\nend","preventionTips":["Always inspect exception.cause before treating this as a Capybara bug","Keep raise_server_errors true; disable only inside narrowly-scoped around-hooks","Narrow Capybara.server_errors when a spec intentionally triggers app errors"],"tags":["server-errors","rack","debugging","exception-cause","app-error"],"backgroundTag":"server-error-propagation","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}