-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathRcloneException.php
More file actions
82 lines (70 loc) · 1.99 KB
/
Copy pathRcloneException.php
File metadata and controls
82 lines (70 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
namespace Verseles\Flyclone\Exception;
use RuntimeException;
/**
* Base exception for all rclone-related errors.
*
* Provides enhanced context including command executed, provider info, and paths.
*/
class RcloneException extends RuntimeException
{
/** @var array<string, mixed> Additional context about the error */
protected array $context = [];
/**
* Set additional context for the exception.
*
* @param array<string, mixed> $context Contextual information (command, provider, path, etc.)
*/
public function setContext(array $context): self
{
$this->context = array_merge($this->context, $context);
return $this;
}
/**
* Get the exception context.
*
* @return array<string, mixed> The context array.
*/
public function getContext(): array
{
return $this->context;
}
/**
* Get a specific context value.
*
* @param string $key The context key.
* @param mixed $default Default value if key doesn't exist.
*
* @return mixed The context value or default.
*/
public function getContextValue(string $key, mixed $default = null): mixed
{
return $this->context[$key] ?? $default;
}
/**
* Check if this exception represents a retryable error.
*
* @return bool True if the operation can be retried.
*/
public function isRetryable(): bool
{
return false;
}
/**
* Get a detailed string representation of the exception.
*
* @return string Detailed exception information.
*/
public function getDetailedMessage(): string
{
$details = [$this->getMessage()];
if (! empty($this->context)) {
$details[] = 'Context:';
foreach ($this->context as $key => $value) {
$details[] = " $key: " . (is_array($value) ? json_encode($value) : $value);
}
}
return implode("\n", $details);
}
}