Skip to content
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

You cannot create React\Promise\FulfilledPromise #996

Closed
Warxcell opened this issue Mar 5, 2015 · 14 comments
Closed

You cannot create React\Promise\FulfilledPromise #996

Warxcell opened this issue Mar 5, 2015 · 14 comments

Comments

@Warxcell
Copy link

Warxcell commented Mar 5, 2015

InvalidArgumentException: You cannot create React\Promise\FulfilledPromise with a promise. Use React\Promise\resolve($promiseOrValue) instead. in /*/vendor/react/promise/src/FulfilledPromise.php on line 12

Any ideas?

@mtdowling
Copy link
Member

Can you give a stack trace?

On Mar 5, 2015, at 6:48 AM, Bozhidar Hristov notifications@github.com wrote:

InvalidArgumentException: You cannot create React\Promise\FulfilledPromise with a promise. Use React\Promise\resolve($promiseOrValue) instead. in /*/vendor/react/promise/src/FulfilledPromise.php on line 12

Any ideas?


Reply to this email directly or view it on GitHub.

@Warxcell
Copy link
Author

Warxcell commented Mar 5, 2015

Of course:

#0 */vendor/guzzlehttp/guzzle/src/RequestFsm.php(173): GuzzleHttp\Exception\RequestException::wrapException(Object(GuzzleHttp\Message\Request), Object(InvalidArgumentException))

#1 */vendor/guzzlehttp/guzzle/src/RequestFsm.php(92): GuzzleHttp\RequestFsm->error(Object(GuzzleHttp\Transaction))

#2 */vendor/guzzlehttp/guzzle/src/Client.php(245): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))
#3 *: GuzzleHttp\Client->send(Object(GuzzleHttp\Message\Request))

Edit: That is from XDebug:

  1. GuzzleHttp\Client->send( )
  2. GuzzleHttp\RequestFsm->__invoke( ) ../Client.php:245
  3. GuzzleHttp\RequestFsm->send( ) ../RequestFsm.php:92
  4. GuzzleHttp\Message\FutureResponse::proxy( ) ../RequestFsm.php:156
  5. GuzzleHttp\Ring\Future\CompletedFutureValue->then( ) ../FutureResponse.php:43
  6. GuzzleHttp\Ring\Future\CompletedFutureValue->promise( ) ../CompletedFutureValue.php:55
  7. React\Promise\FulfilledPromise->__construct( ) ../CompletedFutureValue.php:44

@mtdowling
Copy link
Member

Thanks.

Can you update to the latest version of Guzzle? Is there a reproducible snippet of code you can provide that I can play around with?

@Warxcell
Copy link
Author

Warxcell commented Mar 5, 2015

  • Installing guzzlehttp/guzzle (dev-master 589f187)

Still same problem. The request is very simple:

$body = 'valid xml';
$request = $this->client->createRequest('POST', 'http://localhost:8989', array(
'body' => $body
));

$request->setHeader('Content-Type', 'text/xml');
$response = $this->client->send($request);

BTW I just saw two warnings before exception:

Message: Argument 1 passed to GuzzleHttp\Ring\Future\CompletedFutureArray::__construct() must be of the type array, object given, called in */vendor/guzzlehttp/ringphp/src/Client/CurlHandler.php on line 78 and defined Filename: Future/CompletedFutureArray.php Line Number: 9

@Warxcell
Copy link
Author

Warxcell commented Mar 5, 2015

I just found the problem:
It tries three times to send query and enter here:
return self::retryFailedRewind($handler, $request, $response);
but second time this returns: GuzzleHttp\Ring\Future\CompletedFutureArray, not array.

This is my other question, how can I modify response before ANY validation? I'm integrating with XML API which is returning ALWAYS HTTP Status = 0 ? I need to modify Status to be always 200 so it won't broke Guzzle.

@mtdowling
Copy link
Member

Weird. That could be a bug in Guzzle.

Are you sure that the service actually returns a status of 0? Does setting the status code to something other than 0 cause this problem to go away?

@Warxcell
Copy link
Author

Warxcell commented Mar 5, 2015

Yes, everything is ok with raw curl. Status is 0.

https://github.com/guzzle/RingPHP/blob/master/src/Client/CurlFactory.php#L89
!isset($response['status']) == true so self::createErrorResponse($handler, $request, $response) is called, then

https://github.com/guzzle/RingPHP/blob/master/src/Client/CurlFactory.php#L108 - There is no real error, actually request is succesfull.

https://github.com/guzzle/RingPHP/blob/master/src/Client/CurlFactory.php#L109 = yes, it's empty.

so, it call return self::retryFailedRewind($handler, $request, $response);

internally retryFailedRewing calls recursively https://github.com/guzzle/RingPHP/blob/master/src/Client/CurlHandler.php#L60 which return CompletedFutureArray and outside of that call is wrapped again with CompletedFutureArray

If i set $response['status'] = 200; here https://github.com/guzzle/RingPHP/blob/master/src/Client/CurlFactory.php#L88 everyting works as expected. Is there way to modify this StatusCode with listener just before there?

Also there isn't any headers.

@alcohol
Copy link

alcohol commented Apr 3, 2015

$array["key"] = 0; 
var_dump(isset($array["key"]));

bool(true)

So the problem is not that the status is 0. The problem is that $response['status'] is either

  • not set at all,
  • is set to null.

Can you debug this block?

In particular, this line. If it sets the value to null, that would be why the isset() call returns false.

The following could explain a lot too though, but the statement is rather vague...

Also there isn't any headers.

Can you elaborate? You mean the API you are calling does not return any headers at all?

@Warxcell
Copy link
Author

Warxcell commented Apr 3, 2015

Yes, the remote API we call does not return any headers. This is curl_info:

'content_type' => null
'http_code' => int 0
'header_size' => int 0
'request_size' => int 784

@alcohol
Copy link

alcohol commented Apr 3, 2015

Well... that is one seriously broken API.

@Warxcell
Copy link
Author

Warxcell commented Apr 3, 2015

It's API of payment broker. :)

Data is in XML. (Also the status code)

@alcohol
Copy link

alcohol commented Apr 3, 2015

I don't really know how to deal with this.

If a subscriber with a onComplete hook could capture the request before it does the header validation, then you could simply check if the content contains a valid XML body and return the response using intercept() (or alternatively, add headers that the request should have). But at a quick glance it looks to me like it would already fail before that hook gets triggered.

I would definitely contact your payment broker though and ask them why their API is so broken, and request that they fix it. I've worked with a lot of payment providers in the past, and I have never encountered something like this before.

@Warxcell
Copy link
Author

Warxcell commented Apr 3, 2015

I tried to make them fix it, but they don't want to do it.

I tried and the following:
$this->client->getEmitter()->on('complete', array($this, 'fake'), 'first');
with no success either.

@mtdowling
Copy link
Member

Not returning a status code or headers is not a valid HTTP response. I don't think guzzle needs to be modified to support that type of response. Maybe better error reporting would have been better though, and I'd gladly accept a PR along those lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants