Skip to content

Commit d7533ab

Browse files
committed
Fix missing error handling
1 parent 73fb98a commit d7533ab

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ jobs:
3434
uses: actions/checkout@v4
3535

3636
- name: Psalm
37-
uses: docker://ghcr.io/psalm/psalm-github-actions
37+
uses: docker://ghcr.io/psalm/psalm-github-actions:6.4.1
3838
with:
3939
args: --shepherd
40-
php_version: "8.0"
4140

4241
test:
4342
runs-on: ubuntu-latest

.phive/phars.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpunit" version="^10.0.0" installed="10.5.3" location="./tools/phpunit" copy="true"/>
4-
<phar name="psalm" version="^5.12.0" installed="5.17.0" location="./tools/psalm" copy="true"/>
3+
<phar name="phpunit" version="^10.0.0" installed="10.5.45" location="./tools/phpunit" copy="true"/>
4+
<phar name="psalm" version="~6.4.0" installed="6.4.1" location="./tools/psalm" copy="true"/>
55
<phar name="phpcpd" version="^6.0.0" installed="6.0.3" location="./tools/phpcpd" copy="true"/>
66
</phive>

psalm.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
errorBaseline="psalm.baseline.xml"
88
errorLevel="2"
99
findUnusedBaselineEntry="false"
10-
findUnusedCode="false">
10+
findUnusedCode="false"
11+
phpVersion="8.0">
1112

1213
<projectFiles>
1314
<directory name="src" />

src/LargeArrayBuffer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,17 @@ public function __construct(int $maxMemoryMiB = 1024, int $serializer = self::SE
7979

8080
/**
8181
* @psalm-param E $item
82-
* @throws \RuntimeException if unable to write to php://temp
82+
* @throws \RuntimeException if unable to write to php://temp, the serialization failed or the compression failed
8383
*/
8484
public function push(mixed $item): void {
8585
$serialized = match($this->serializer){
8686
self::SERIALIZER_IGBINARY => igbinary_serialize($item),
8787
self::SERIALIZER_MSGPACK => msgpack_serialize($item),
8888
default => serialize($item)
8989
};
90+
if($serialized === false){
91+
throw new \RuntimeException('failed to serialize data');
92+
}
9093
/** @var string|false $compressed */
9194
$compressed = match($this->compression){
9295
self::COMPRESSION_GZIP => gzdeflate($serialized),
@@ -219,7 +222,14 @@ public function toJSONFile($dest, int $flags = JSON_THROW_ON_ERROR, int $depth =
219222
if(($flags & JSON_PRETTY_PRINT) > 0){
220223
fwrite($stream, PHP_EOL.' ');
221224
}
222-
fwrite($stream, json_encode($item, $flags, $depth));
225+
$json = json_encode($item, $flags, $depth);
226+
if($json === false){
227+
if(is_string($dest)){
228+
fclose($stream);
229+
}
230+
throw new \RuntimeException('failed to serialize data');
231+
}
232+
fwrite($stream, $json);
223233
fflush($stream);
224234
$first = false;
225235
}

0 commit comments

Comments
 (0)