Skip to content

Commit dd775b4

Browse files
committed
Correct handling of missing files for StreamFactory
1 parent 839e68e commit dd775b4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
composer.phar
22
composer.lock
33
phpunit.xml
4+
.phpunit.result*
45
build/
56
vendor/

src/StreamFactory.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,20 @@ public function createStream(string $content = ''): StreamInterface
1919

2020
public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
2121
{
22-
$resource = fopen($file, $mode);
22+
try {
23+
$resource = fopen($file, $mode);
24+
} catch (\Throwable $e) {
25+
throw new \RuntimeException(
26+
sprintf(
27+
'Unable to open "%s" using mode "%s": "%s',
28+
$file,
29+
$mode,
30+
$e->getMessage(),
31+
),
32+
0,
33+
$e,
34+
);
35+
}
2336

2437
return $this->createStreamFromResource($resource);
2538
}

0 commit comments

Comments
 (0)