Skip to content

Commit 09669de

Browse files
author
David Vandemaele
committed
Only allow output string instead of exception when logging
1 parent 98aa272 commit 09669de

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

lib/Skeleton/Transaction/Log.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,14 @@ public static function get_last_successful() {
8989
* Create log.
9090
*/
9191
public static function create(
92-
\Transaction $transaction, bool $failed, string $output = '', ?\Throwable $t = null,
93-
?string $date = null
92+
\Transaction $transaction, bool $failed, string $output = '', ?string $date = null
9493
): self {
9594

9695
$log = new self();
9796
$log->transaction_id = $transaction->id;
9897
$log->failed = $failed;
9998
$log->output = $output;
10099

101-
if (isset($t) === true) {
102-
$log->exception = print_r($t, true);
103-
}
104-
105100
if ($date !== null) {
106101
$log->created = (new \DateTime($date))->format('Y-m-d H:i:s');
107102
}

lib/Skeleton/Transaction/Retry.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ trait Retry {
2323
* Retry transaction after a specified time (default: 15 minutes)
2424
*
2525
* @access public
26-
* @param \Exception $exception
2726
* @param string $output
2827
* @param string $next_retry
2928
*/
30-
public function retry(\Exception $exception = null, $output = null, $next_retry = '+15 minutes') {
29+
public function retry($output = null, $next_retry = '+15 minutes') {
3130
if (self::$max_attempts > 0 && $this->retry_attempt >= self::$max_attempts) {
32-
echo $output;
33-
throw $exception;
31+
throw new \Exception($output);
3432
}
3533

36-
Log::create($this, true, $output, $exception);
34+
Log::create($this, true, $output);
3735

3836
$this->retry_attempt++;
3937
$this->schedule($next_retry);
@@ -43,18 +41,16 @@ public function retry(\Exception $exception = null, $output = null, $next_retry
4341
* Retry transaction using an incremental time algorithm
4442
*
4543
* @access public
46-
* @param \Exception $exception
4744
* @param string $output
4845
* @param int $exp
4946
* @param string $unit
5047
*/
51-
public function retry_incremental(\Exception $exception = null, $output = null, $exp = 2, $unit = 'minutes') {
48+
public function retry_incremental($output = null, $exp = 2, $unit = 'minutes') {
5249
if (self::$max_attempts > 0 && $this->retry_attempt >= self::$max_attempts) {
53-
echo $output;
54-
throw $exception;
50+
throw new \Exception($output);
5551
}
5652

57-
Log::create($this, true, $output, $exception);
53+
Log::create($this, true, $output);
5854

5955
$this->retry_attempt++;
6056
$this->schedule(pow($this->retry_attempt, $exp) . ' ' . $unit);

lib/Skeleton/Transaction/Transaction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function unlock() {
209209
* @access public
210210
*/
211211
public function mark_failed($output, $exception, $date = null) {
212-
Log::create($this, true, $output, $exception, $date);
212+
Log::create($this, true, print_r($exception, true), $date);
213213

214214
$this->failed = true;
215215
$this->completed = true;
@@ -229,8 +229,8 @@ public function mark_failed($output, $exception, $date = null) {
229229
* @param string $date
230230
*/
231231
public function mark_completed($output, $date = null) {
232-
Log::create($this, false, $output, null, $date);
233-
232+
Log::create($this, false, $output, $date);
233+
234234
// Don't mark this transaction as completed if it has been rescheduled.
235235
if ($this->rescheduled) {
236236
return;

0 commit comments

Comments
 (0)