Skip to content

The driver does not throw an exception when an http error is returned from selenium #57

Closed

Description

@gggeek

The problem seems to be due to a missing CURLOPT_FAILONERROR option being set by default.
Without that, curl_errno and curl_error do not deliver anything, and the code will let the bad selenium response float all the way up to the upper layers of the testing application.

First noticed while testing using the SauceLabs service. See details here: Behat/MinkExtension#179

Activity

  1. aik099 commented on Dec 4, 2014

    @aik099
    Contributor

    @gggeek , according to http://php.net/manual/en/function.curl-setopt.php the CURLOPT_FAILONERROR option is disabled by default in curl and needs to be manually enabled for exception to be thrown in case if curl encounters an error.

  2. gggeek commented on Dec 4, 2014

    @gggeek
    ContributorAuthor

    @aik099 nowhere in that page an exception is mentioned. And curl was in php before exceptions where :-), so no. Plus if you look at user comments in the manual page for curl_error(), some people mention that it will not return anything unless CURLOPT_FAILONERROR has been set. And of course I tested it on at least one platform (php 5.4 from debian 7), and that was true for both curl_error() and curl_errno()

  3. aik099 commented on Dec 4, 2014

    @aik099
    Contributor

    I've never set CURLOPT_FAILONERROR option and had $GLOBALS['curl_error'] populated. Maybe this behavior was changed in recent curl versions.

  4. robocoder commented on Dec 4, 2014

    @robocoder
    Contributor

    Setting CURLOPT_FAILONERROR won't handle every 4xx code. From the curl documentation:

    This method is not fail-safe and there are occasions where non-successful response codes will slip through, especially when authentication is involved (response codes 401 and 407).

    You might get some amounts of headers transferred before this situation is detected, like when a "100-continue" is received as a response to a POST/PUT and a 401 or 407 is received immediately afterwards.

  5. gggeek commented on Dec 5, 2014

    @gggeek
    ContributorAuthor

    @aik099 interesting. I've myself never used $GLOBALS['curl_error'] as I prefer not to use global variables if I can.
    In fact I just checked the networking code of the phpxmlrpc library, which I have been maintaining since forever and is definitely battle-tested, and there is no use of curl_errno() or CURLOPT_FAILONERROR either. But there I can safely declare all empty response bodies as error; whereas I am not sure if such a simple approach is good here. The other way is to check by hand the http header returned. Maybe it is worth looking at how guzzle and company do the same check?

    @robocoder I am not totally familiar with the webdriver protocol. is it ever supposed to use auth schemes involviung 401/407 responses? I see no mention of auth in the spec ( https://code.google.com/p/selenium/wiki/JsonWireProtocol )

  6. aik099 commented on Dec 7, 2014

    @aik099
    Contributor

    @gggeek , sorry for misleading you. I've just checked my code again and I'm using curl_errno($ch) and curl_error($ch) before connection is closed to get error information within my wrapper around curl library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions