Skip to content

Commit

Permalink
Fix shmop error handling
Browse files Browse the repository at this point in the history
Behavior changed in PHP 8.0.
  • Loading branch information
kelunik committed Aug 19, 2023
1 parent f6fe35f commit 50ddc73
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/SharedMemoryParcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,13 @@ private function readSegment(int $offset, int $size): string
{
\assert($this->handle !== null);

/** @psalm-suppress InvalidArgument Psalm needs to be updated for ext-shmop using objects. */
return \shmop_read($this->handle, $offset, $size);
try {
return \shmop_read($this->handle, $offset, $size);
} catch (\ValueError $error) {
throw new ParcelException(
'Failed to read from shared memory block: ' . ($error->getMessage() ?? 'unknown error')
);
}
}

/**
Expand All @@ -392,11 +397,11 @@ private function writeSegment(string $data): void
{
\assert($this->handle !== null);

/** @psalm-suppress InvalidArgument Psalm needs to be updated for ext-shmop using objects. */
if (!\shmop_write($this->handle, $data, 0)) {
$error = \error_get_last();
try {
\shmop_write($this->handle, $data, 0);
} catch (\ValueError $error) {
throw new ParcelException(
'Failed to write to shared memory block: ' . ($error['message'] ?? 'unknown error')
'Failed to write to shared memory block: ' . ($error->getMessage() ?? 'unknown error')
);
}
}
Expand Down

0 comments on commit 50ddc73

Please sign in to comment.