Skip to content

Commit 75adfbd

Browse files
chore: minor validations
1 parent 6a97b40 commit 75adfbd

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/Retry/ConfigurationProvider.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,19 @@ public static function env(): callable
107107
return function () {
108108
// Use config from environment variables, if available
109109
$mode = getenv(self::ENV_MODE);
110-
$maxAttempts = getenv(self::ENV_MAX_ATTEMPTS) ?: self::DEFAULT_MAX_ATTEMPTS;
111-
if (!empty($mode)) {
112-
return Promise\Create::promiseFor(
113-
new Configuration($mode, $maxAttempts)
114-
);
110+
if ($mode === false || $mode === '') {
111+
return self::reject('Could not find environment variable config'
112+
. ' in ' . self::ENV_MODE);
115113
}
116114

117-
return self::reject('Could not find environment variable config'
118-
. ' in ' . self::ENV_MODE);
115+
$maxAttempts = getenv(self::ENV_MAX_ATTEMPTS);
116+
$maxAttempts = ($maxAttempts !== false && $maxAttempts !== '')
117+
? $maxAttempts
118+
: self::DEFAULT_MAX_ATTEMPTS;
119+
120+
return Promise\Create::promiseFor(
121+
new Configuration($mode, $maxAttempts)
122+
);
119123
};
120124
}
121125

src/S3/S3Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ public static function isDirectoryBucket(string $bucket): bool
10191019
}
10201020

10211021
/** @internal */
1022-
public static function _applyRetryConfig(mixed $value, array $args, HandlerList $list): void
1022+
public static function _applyRetryConfig(mixed $value, array &$args, HandlerList $list): void
10231023
{
10241024
if ($value) {
10251025
$config = \Aws\Retry\ConfigurationProvider::unwrap($value);
@@ -1028,14 +1028,14 @@ public static function _applyRetryConfig(mixed $value, array $args, HandlerList
10281028
$maxRetries = $config->getMaxAttempts() - 1;
10291029
$decider = RetryMiddleware::createDefaultDecider($maxRetries);
10301030
$decider = function ($retries, $command, $request, $result, $error) use ($decider, $maxRetries) {
1031-
$maxRetries = $command['@retries'] ?? $maxRetries;
1031+
$effectiveMaxRetries = $command['@retries'] ?? $maxRetries;
10321032

10331033
if ($decider($retries, $command, $request, $result, $error)) {
10341034
return true;
10351035
}
10361036

10371037
if ($error instanceof AwsException
1038-
&& $retries < $maxRetries
1038+
&& $retries < $effectiveMaxRetries
10391039
) {
10401040
if ($error->getResponse()
10411041
&& $error->getResponse()->getStatusCode() >= 400

0 commit comments

Comments
 (0)