{"record":{"id":"b380a97e6ce61951","repo":"moodle/moodle","slug":"expected-an-aws-resultinterface-or-exception","errorCode":null,"errorMessage":"Expected an Aws\\ResultInterface or Exception.","messagePattern":"Expected an Aws\\\\ResultInterface or Exception\\.","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"public/lib/aws-sdk/src/MockHandler.php","lineNumber":58,"sourceCode":"        if ($resultOrQueue) {\n            call_user_func_array([$this, 'append'], array_values($resultOrQueue));\n        }\n    }\n\n    /**\n     * Adds one or more variadic ResultInterface or AwsException objects to the\n     * queue.\n     */\n    public function append()\n    {\n        foreach (func_get_args() as $value) {\n            if ($value instanceof ResultInterface\n                || $value instanceof Exception\n                || is_callable($value)\n            ) {\n                $this->queue[] = $value;\n            } else {\n                throw new \\InvalidArgumentException('Expected an Aws\\ResultInterface or Exception.');\n            }\n        }\n    }\n\n    /**\n     * Adds one or more \\Exception or \\Throwable to the queue\n     */\n    public function appendException()\n    {\n        foreach (func_get_args() as $value) {\n            if ($value instanceof \\Exception || $value instanceof \\Throwable) {\n                $this->queue[] = $value;\n            } else {\n                throw new \\InvalidArgumentException('Expected an \\Exception or \\Throwable.');\n            }\n        }\n    }\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/aws-sdk/src/MockHandler.php#L40-L76","documentation":"MockHandler::append() only accepts values that are AWS ResultInterface objects, Exception/Throwable instances, or callables, since those are the only things it can return when the handler is invoked. Any other queued value (e.g. a raw array, a string, or an SDK Model object created before the result exists) is rejected with InvalidArgumentException at queue-append time rather than failing later during the mocked send.","triggerScenarios":"Calling $mock->append(['key' => 'value']) with a plain array, appending a string, null, or an arbitrary object, or appending a value that implements neither ResultInterface, Exception, nor __invoke while configuring a mocked AWS client.","commonSituations":"Test setups where developers copy examples that queue arrays; hand-built fake responses not wrapped in Result::fromArray; migrating test code from other HTTP mocking libraries (Guzzle MockHandler accepts arrays/responses, AWS MockHandler does not).","solutions":["Wrap plain response data in Aws\\Result before appending: $mock->append(new Result(['Foo' => 'bar'])).","If you intend an error, append an Aws\\Exception or Aws\\Result implementing object instead of a string/array.","For dynamic behavior, append a callable: $mock->append(function (CommandInterface $cmd, RequestInterface $req) { return new Result([...]); }).","Check that the value class actually implements Aws\\ResultInterface (e.g. it is an Aws\\Result, not an array or Guzzle response)."],"exampleFix":"// before\n$mock->append(['Products' => []]);\n\n// after\n$mock->append(new \\Aws\\Result(['Products' => []]));","handlingStrategy":"validation","validationCode":"if (!$value instanceof \\Aws\\ResultInterface && !$value instanceof \\Exception && !is_callable($value)) { throw new \\InvalidArgumentException('append() requires ResultInterface, Exception, or callable'); }","typeGuard":"function isQueueableMockOutcome($v): bool { return $v instanceof \\Aws\\ResultInterface || $v instanceof \\Exception || is_callable($v); }","tryCatchPattern":"try { $mock->append($value); } catch (\\InvalidArgumentException $e) { $mock->append(new \\Aws\\Result((array) $value)); }","preventionTips":["Always wrap raw response arrays in new Aws\\Result([...]) before appending","Remember AWS MockHandler does not accept Guzzle responses or arrays, unlike Guzzle's MockHandler","Add a small test helper that validates queued values before appending"],"tags":["aws-sdk","mocking","invalid-argument","testing"],"backgroundTag":"invalid-argument-value","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}