Skip to content

Make sure we always have a stack #134

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

Merged
merged 3 commits into from
Feb 23, 2017
Merged

Make sure we always have a stack #134

merged 3 commits into from
Feb 23, 2017

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Feb 22, 2017

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets fixes #133
Documentation n/a
License MIT

What's in this PR?

If we (for some reason) do not have a stack, it should not crash. Just pretend everything is normal.

@dkvk, does this patch solve your issue?

Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

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

is it "legal" that we have no stack? or should that never happen?

@@ -58,7 +58,9 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
{
$profile = new Profile($this->pluginName, $this->formatter->formatRequest($request));

$this->collector->getCurrentStack()->addProfile($profile);
if (false !== $stack = $this->collector->getCurrentStack()) {

Choose a reason for hiding this comment

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

In addition to @dbu's #134 (review): as getCurrentStack() either returns a Stack or not, would

if ($stack = $this->collector->getCurrentStack()) {

perhaps suffice?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the reivew. You are correct. I should update.

We are trying out https://app.assignees.io/. A service that automatically finds the best reviewer. Somehow it selected you.

Choose a reason for hiding this comment

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

Because it somehow knows that I'm a nitpicker and micromanager 😂🙈. Scary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i would write it like jerome proposes, thats simpler to read.

the question remains if this situation can ever happen. maybe we should instead have getCurrentStack throw an exception if there is no current stack. that is more disruptive but would force to figure out why it happens.

though maybe as this is just a debugging tool, we should rather silently fail than make a noise about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Silently fail will just hide details in the profiler, but it may be hard for users to find why my plugin is not in the profiler.

Throwing a LogicException may do the job unless I missed some cases while refactoring the profiler.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 22, 2017

is it "legal" that we have no stack? or should that never happen?

To be honest, I do not know. Im not sure how we can be in ProfilerPlugin without a stack. @fbourigault do you know?

@fbourigault
Copy link
Contributor

fbourigault commented Feb 22, 2017

It should never happen as the StackPlugin is inserted to be the very first plugin (and it's not a decorated plugin).

@Nyholm I agree with those changes, but I'm a bit curious about how @dkvk ran into this issue. In https://github.com/php-http/HttplugBundle/blob/master/DependencyInjection/HttplugExtension.php#L289-L308 every plugin is decorated with a ProfilePlugin and then a StackPlugin is added at the top.

EDIT: Maybe we could log some warning here as it's not a normal situation.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 22, 2017

What if you:

$plugin = $this->container->get('httplug.plugin.logger');
$client = new PluginClient($httpClient, [$plugin]);

But that's not how Daniel did it...

@fbourigault
Copy link
Contributor

This is not a problem as the plugin doesn't get decorated.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 23, 2017

I'll merge this and tag a patch release. Having a request missing from the profile is better than causing errors

@dbu
Copy link
Collaborator

dbu commented Feb 23, 2017 via email

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

Successfully merging this pull request may close these issues.

There's not always a Stack on the Collector
5 participants