Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Ensure that MiddlewarePipes are called as callables if an error is present #95

Merged

Conversation

weierophinney
Copy link
Member

As reported in zendframework/zend-expressive#416, error middleware nested inside a MiddlewarePipe was not being dispatched. This was due to the fact that Dispatch was identifying the pipeline as http-interop middleware, and thus dropping the $err argument (as interop middleware cannot accept that argument).

Theis patch updates Dispatch to check if the middleware is a MiddlewarePipe and a non-null $err is present; if so, it now dispatches it as callable middleware instead of as interop middleware.

…esent

As reported in zendframework/zend-expressive#416, error middleware
nested inside a `MiddlewarePipe` was not being dispatched. This was due
to the fact that `Dispatch` was identifying the pipeline as http-interop
middleware, and thus dropping the `$err` argument (as interop middleware
cannot accept that argument).

Theis patch updates `Dispatch` to check if the middleware is a
`MiddlewarePipe` and a non-null `$err` is present; if so, it now
dispatches it as callable middleware instead of as interop middleware.
@weierophinney weierophinney added this to the 1.3.2 milestone Jan 5, 2017
*/
public function testInvokingWithMiddlewarePipeAndErrorDispatchesNextErrorMiddleware()
{
$error = new RuntimeException('expected');
Copy link
Member

Choose a reason for hiding this comment

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

Consider using just Exception. Even better, Throwable may be needed

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll rewrite to use a data provider to seed multiple exception/throwable types. Thanks for the feedback!

@@ -442,6 +442,99 @@ public function testInvokingWithInteropMiddlewareDispatchesIt()
}

/**
* @todo Remove this test for version 2.0
Copy link
Member

Choose a reason for hiding this comment

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

Should probably spawn an issue for 2.0 for this, then link the issue instead

Copy link
Member

Choose a reason for hiding this comment

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

Also: why is this not needed in 2.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this class goes away entirely, and that version will only work with http-interop middleware. 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Which means, really, that this @todo can go away, as the top of the classfile already indicates the entire file goes away. Updating...

}

/**
* @todo Remove this test for version 2.0
Copy link
Member

Choose a reason for hiding this comment

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

Should probably spawn an issue for 2.0 for this, then link the issue instead

Copy link
Member Author

Choose a reason for hiding this comment

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

See note above; I'll just remove these, as there's a note at the top of this file already.

@weierophinney
Copy link
Member Author

@Ocramius Feedback incorporated; waiting for build, but should be ready for you to review.

@Ocramius Ocramius self-assigned this Jan 5, 2017
@Ocramius Ocramius merged commit eefbe51 into zendframework:master Jan 5, 2017
Ocramius added a commit that referenced this pull request Jan 5, 2017
@Ocramius
Copy link
Member

Ocramius commented Jan 5, 2017

@weierophinney awesome, thanks!

Note that this cannot be forward ported, as develop has no Dispatch class anymore.

@weierophinney
Copy link
Member Author

Note that this cannot be forward ported, as develop has no Dispatch class anymore.

Yep - and hence the reason I could omit the TODO items. 😄 Should not affect merging from develop to master later.

Thanks for the review; I'll get a tag out shortly.

@weierophinney weierophinney deleted the hotfix/middleware-pipe-errors branch January 5, 2017 22:20
@Ocramius
Copy link
Member

Ocramius commented Jan 5, 2017

@weierophinney I'm currently tagging: want me to hold back?

@weierophinney
Copy link
Member Author

Nope, go ahead, @Ocramius.

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

Successfully merging this pull request may close these issues.

None yet

2 participants