Skip to content

Commit 3a85d2b

Browse files
authored
Fix error handling on stream reading (#27)
1 parent 6d86446 commit 3a85d2b

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# HTTP Message Change Log
22

3+
## 1.1.1 - Under development
4+
5+
### Fixed
6+
7+
- [#27](https://github.com/httpsoft/http-message/pull/27) Fix error handling on stream reading
8+
39
## 1.1.1 - 2023.05.06
410

511
### Fixed

psalm.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<psalm
33
errorLevel="1"
44
findUnusedPsalmSuppress="true"
5+
findUnusedBaselineEntry="true"
6+
findUnusedCode="false"
57
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
68
xmlns="https://getpsalm.org/schema/config"
79
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

src/StreamTrait.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use InvalidArgumentException;
88
use RuntimeException;
9+
use Throwable;
910

1011
use function array_key_exists;
1112
use function fclose;
@@ -354,7 +355,12 @@ public function getMetadata($key = null)
354355
return $key ? null : [];
355356
}
356357

357-
$metadata = stream_get_meta_data($this->resource);
358+
try {
359+
$metadata = stream_get_meta_data($this->resource);
360+
} catch (Throwable $e) {
361+
$this->detach();
362+
throw new RuntimeException('Unable to read stream contents: ' . $e->getMessage());
363+
}
358364

359365
if ($key === null) {
360366
return $metadata;

src/Uri.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ private function normalizeFragment(string $fragment): string
506506
* @param string $string
507507
* @param string $pattern
508508
* @return string
509+
*
510+
* @psalm-param non-empty-string $pattern
509511
*/
510512
private function encode(string $string, string $pattern): string
511513
{

0 commit comments

Comments
 (0)