moodle/moodle · error · InvalidArnException
Constructor accepts a string or an array as an argument.
Error message
Constructor accepts a string or an array as an argument.
What it means
Arn::__construct() only accepts a string (which it parses) or an array of already-parsed components; any other type (null, int, object) throws InvalidArnException. It is a constructor input-type guard.
Solutions
- Ensure the value is a string ARN or an associative array of parsed components before constructing.
- Coerce with (string) if it's a scalar, after verifying it isn't null.
- Check upstream config/env for the missing ARN value.
- Type-check: if (!is_string($arn) && !is_array($arn)) fail early in your code.
Example fix
// before
$arn = new Arn($config['role_arn']); // may be null
// after
if (!is_string($config['role_arn'] ?? null)) {
throw new \Exception('role_arn must be a string');
}
$arn = new Arn($config['role_arn']); Defensive patterns
Strategy: type-guard
Validate before calling
if (!is_string($data) && !is_array($data)) throw new \Exception('ARN must be string or array'); Type guard
function isArnInput($v): bool { return is_string($v) || is_array($v); } Try / catch
try { $arn = new Arn($data); } catch (InvalidArnException $e) { // log type of $data, fix upstream config } Prevention
- Assert config values are non-null strings at boot
- Use ?? '' defaults plus explicit emptiness checks
- Type-hint parameters in your own code (string $arn)
When it happens
Trigger: Passing null (e.g. from an unset config value or failed lookup) into new Arn(...), passing an integer or object instead of a string/array.
Common situations: Config values that resolve to null, passing the result of a function that returns mixed, typos where the variable holding the ARN string was never assigned.
Related errors
- ARN values cannot be used in the bucket field for the
- Bucket parameter parsed as ARN and failed with
- Credentials must be an instance of ' …
- Fips is currently not supported with S3 Outposts access…
- Invalid configuration value provided for…
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/001312601262a371.
Report an issue: GitHub.
Appendix: source
Thrown at public/lib/aws-sdk/src/Arn/Arn.php:66
} else {
// If there are < 5 components, put remainder in current
// component.
$data[key($data)] = substr($string, $lastDelim);
}
}
}
return $data;
}
public function __construct($data)
{
if (is_array($data)) {
$this->data = $data;
} elseif (is_string($data)) {
$this->data = static::parse($data);
} else {
throw new InvalidArnException('Constructor accepts a string or an'
. ' array as an argument.');
}
static::validate($this->data);
}
public function __toString()
{
if (!isset($this->string)) {
$components = [
$this->getPrefix(),
$this->getPartition(),
$this->getService(),
$this->getRegion(),
$this->getAccountId(),
$this->getResource(),
];
View on GitHub (pinned to 48ea8c3322)