Skip to content

ext/curl: curl_error using curl_easy_strerror if CURLOPT_ERRORBUFFER #14984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

devnexen
Copy link
Member

did not fill the error buffer.

@devnexen
Copy link
Member Author

Linked to GH-14915. IMHO the analysis nearly got it right (about the solution). I took it as feature request rather than bug though cc @adoy.

@adoy
Copy link
Member

adoy commented Jul 16, 2024

I think it's ok to treat this as a new feature. Someone could easily call
curl_strerror(curl_errno()) if string is empty and code will still work later when upgraded to PHP8.4+.

@Ayesh
Copy link
Member

Ayesh commented Jul 16, 2024

I also read the issue and was trying a fix like this. Pleasant surprise to see this PR!

I'd argue that this is in fact a bug fix.

// curl_exec($ch);
if (curl_error($ch)) {
  throw new \RuntimeException();
}

Snippets like this expect curl_error to return a truthy value (which "" is not), so unless Curl has a custom error message (like "Unable to resolve hostname: abcde") unrecognized errors do not trigger the exception; This is likely unexpected behavior.

@devnexen
Copy link
Member Author

devnexen commented Jul 17, 2024

As mentioned above, it can be circumvented and this error occurs only on rare occasion and if the curl backend does not set the error (ie failf) for the defined case. Pretty difficult to be tested ("unfortunately" error buffer is handled internally :)) but I ll ask @Girgias if I should consider it as bug instead.

@devnexen devnexen marked this pull request as ready for review July 17, 2024 19:28
@devnexen devnexen requested a review from adoy as a code owner July 17, 2024 19:28
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is indeed more of a bugfix than a feature.

It is quite weird that an empty string may be returned when an error has indeed occurred.

@devnexen devnexen closed this in efd00b8 Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants