Skip to content

Commit 51b7788

Browse files
committed
Tweak exception message and return early if response is not an untagged response
1 parent 9d00c90 commit 51b7788

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/MessageQuery.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ public function findOrFail(int $id, ImapFetchIdentifier $identifier = ImapFetchI
190190
*/
191191
public function find(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): ?MessageInterface
192192
{
193-
/** @var UntaggedResponse $response */
194193
$response = $this->id($id, $identifier)->first();
195-
if (! $response) {
194+
195+
if (! $response instanceof UntaggedResponse) {
196196
return null;
197197
}
198198

@@ -298,7 +298,11 @@ protected function fetch(Collection $messages): array
298298
$data = $response->tokenAt(3);
299299

300300
if (! $data instanceof ListData) {
301-
throw new RuntimeException('Invalid data type at index 3');
301+
throw new RuntimeException(sprintf(
302+
'Expected instance of %s at index 3 in FETCH response, got %s',
303+
ListData::class,
304+
get_debug_type($data)
305+
));
302306
}
303307

304308
$uid = $data->lookup('UID')->value;

0 commit comments

Comments
 (0)