Skip to content

Commit

Permalink
Fix cancellation trace recording in TracingDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Oct 26, 2019
1 parent cf12c1c commit 64e7d10
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/Loop/TracingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,18 @@ public function enable(string $watcherId)
} catch (InvalidWatcherError $e) {
throw new InvalidWatcherError(
$watcherId,
$e->getMessage() . "\r\n\r\nCreation Trace:\r\n" . $this->getCreationTrace($watcherId) . "\r\n\r\nCancel Trace:\r\n" . $this->getCancelTrace($watcherId)
$e->getMessage() . "\r\n\r\n" . $this->getTraces($watcherId)
);
}
}

public function cancel(string $watcherId)
{
$this->driver->cancel($watcherId);
$this->creationTraces[$watcherId] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));

if (!isset($this->cancelTraces[$watcherId])) {
$this->cancelTraces[$watcherId] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));
}

unset($this->enabledWatchers[$watcherId], $this->unreferencedWatchers[$watcherId]);
}
Expand All @@ -128,7 +131,7 @@ public function reference(string $watcherId)
} catch (InvalidWatcherError $e) {
throw new InvalidWatcherError(
$watcherId,
$e->getMessage() . "\r\n\r\nCreation Trace:\r\n" . $this->getCreationTrace($watcherId)
$e->getMessage() . "\r\n\r\n" . $this->getTraces($watcherId)
);
}
}
Expand Down Expand Up @@ -205,10 +208,16 @@ protected function deactivate(Watcher $watcher)
// nothing to do in a decorator
}

private function getTraces(string $watcherId): string
{
return "Creation Trace:\r\n" . $this->getCreationTrace($watcherId) . "\r\n\r\n" .
"Cancellation Trace:\r\n" . $this->getCancelTrace($watcherId);
}

private function getCreationTrace(string $watcher): string
{
if (!isset($this->creationTraces[$watcher])) {
throw new InvalidWatcherError($watcher, "An invalid watcher has been used: " . $watcher);
return 'No creation trace, yet.';
}

return $this->creationTraces[$watcher];
Expand All @@ -217,7 +226,7 @@ private function getCreationTrace(string $watcher): string
private function getCancelTrace(string $watcher): string
{
if (!isset($this->cancelTraces[$watcher])) {
throw new InvalidWatcherError($watcher, "An invalid watcher has been used: " . $watcher);
return 'No cancellation trace, yet.';
}

return $this->cancelTraces[$watcher];
Expand Down

0 comments on commit 64e7d10

Please sign in to comment.