Skip to content

Commit

Permalink
Fix error handling on stream reading (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 15, 2023
1 parent 6d86446 commit 3a85d2b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# HTTP Message Change Log

## 1.1.1 - Under development

### Fixed

- [#27](https://github.com/httpsoft/http-message/pull/27) Fix error handling on stream reading

## 1.1.1 - 2023.05.06

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<psalm
errorLevel="1"
findUnusedPsalmSuppress="true"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
8 changes: 7 additions & 1 deletion src/StreamTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use InvalidArgumentException;
use RuntimeException;
use Throwable;

use function array_key_exists;
use function fclose;
Expand Down Expand Up @@ -354,7 +355,12 @@ public function getMetadata($key = null)
return $key ? null : [];
}

$metadata = stream_get_meta_data($this->resource);
try {
$metadata = stream_get_meta_data($this->resource);
} catch (Throwable $e) {
$this->detach();
throw new RuntimeException('Unable to read stream contents: ' . $e->getMessage());
}

if ($key === null) {
return $metadata;
Expand Down
2 changes: 2 additions & 0 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ private function normalizeFragment(string $fragment): string
* @param string $string
* @param string $pattern
* @return string
*
* @psalm-param non-empty-string $pattern
*/
private function encode(string $string, string $pattern): string
{
Expand Down

0 comments on commit 3a85d2b

Please sign in to comment.