Skip to content

Commit 1a2ff80

Browse files
authored
Merge pull request #2 from apacheborys/bug/file-transport-undefined-index-in-howManyTries-method
Bug/file transport undefined index in how many tries method
2 parents 648e6b7 + 03f7a2c commit 1a2ff80

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/BasicExecutor/CommandExecutor.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ApacheBorys\Retry\Entity\Config;
77
use ApacheBorys\Retry\Entity\Message;
88
use ApacheBorys\Retry\Interfaces\Executor;
9+
use Throwable;
910

1011
class CommandExecutor implements Executor
1112
{
@@ -67,7 +68,7 @@ public function handle(Message $message): bool
6768
}
6869

6970
$returnValue = proc_close($process);
70-
} catch (\Throwable $e) {
71+
} catch (Throwable $e) {
7172
$this->rollbackEnvironmentVariables();
7273

7374
throw $e;
@@ -79,26 +80,30 @@ public function handle(Message $message): bool
7980
return $returnValue !== -1;
8081
}
8182

82-
public function compilePayload(\Throwable $exception, Config $config): array
83+
public function compilePayload(Throwable $exception, Config $config): array
8384
{
8485
$result = [];
8586

8687
foreach ($this->arguments as $argName => $argRegExp) {
87-
preg_match($argRegExp, $exception->getMessage(), $matches);
88-
if ($matches && isset($matches[0])) {
89-
$result[$argName] = $matches[0];
88+
$matches = [];
89+
90+
try {
91+
preg_match($argRegExp, $exception->getMessage(), $matches);
92+
} catch (Throwable $e) {
9093
}
94+
95+
$result[$argName] = count($matches) > 0 ? $matches[0] : $argRegExp;
9196
}
9297

9398
return $result;
9499
}
95100

96-
public function getCorrelationId(\Throwable $exception, Config $config): string
101+
public function getCorrelationId(Throwable $exception, Config $config): string
97102
{
98103
$id = getenv(self::ALIAS_FOR_CORRELATION_ID);
99104

100105
if (!$id) {
101-
$config->getTransport()->getNextId($exception, $config);
106+
$id = $config->getTransport()->getNextId($exception, $config);
102107
}
103108

104109
return (string) $id;

src/BasicExecutor/HttpExecutor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getCorrelationId(\Throwable $exception, Config $config): string
9797
$id = $_SERVER['HTTP_' . self::CID] ?? apache_request_headers()[self::CID] ?? null;
9898

9999
if (!$id) {
100-
$config->getTransport()->getNextId($exception, $config);
100+
$id = $config->getTransport()->getNextId($exception, $config);
101101
}
102102

103103
return (string) $id;

src/BasicTransport/FileTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function howManyTriesWasBefore(\Throwable $exception, Config $config): in
133133

134134
$correlationId = $config->getExecutor()->getCorrelationId($exception, $config);
135135

136-
$keysFromIndex = array_keys($this->fileIndexPosition[$correlationId]);
136+
$keysFromIndex = array_keys($this->fileIndexPosition[$correlationId] ?? []);
137137

138138
return isset($this->fileIndexPosition[$correlationId]) && count($keysFromIndex) > 0 ? max($keysFromIndex) : 0;
139139
}

0 commit comments

Comments
 (0)