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

  1. Ensure the value is a string ARN or an associative array of parsed components before constructing.
  2. Coerce with (string) if it's a scalar, after verifying it isn't null.
  3. Check upstream config/env for the missing ARN value.
  4. 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

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


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)