File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 11CHANGELOG
22=========
33
4+ 1.12.0
5+ -------------------
6+
7+ * Improve the error handling when the user tries to open a directory
8+ with the pure PHP reader.
9+
4101.11.1 (2023-12-01)
511-------------------
612
Original file line number Diff line number Diff line change @@ -79,6 +79,13 @@ public function __construct(string $database)
7979 );
8080 }
8181
82+ if (is_dir ($ database )) {
83+ // This matches the error that the C extension throws.
84+ throw new InvalidDatabaseException (
85+ "Error opening database file ( $ database). Is this a valid MaxMind DB file? "
86+ );
87+ }
88+
8289 $ fileHandle = @fopen ($ database , 'rb ' );
8390 if ($ fileHandle === false ) {
8491 throw new \InvalidArgumentException (
Original file line number Diff line number Diff line change @@ -305,6 +305,13 @@ public function testNonDatabase(): void
305305 new Reader ('README.md ' );
306306 }
307307
308+ public function testOpeningDir (): void
309+ {
310+ $ this ->expectException (InvalidDatabaseException::class);
311+ $ this ->expectExceptionMessage ('Error opening database file (tests/). Is this a valid MaxMind DB file? ' );
312+ new Reader ('tests/ ' );
313+ }
314+
308315 public function testTooManyConstructorArgs (): void
309316 {
310317 $ this ->expectException (\ArgumentCountError::class);
You can’t perform that action at this time.
0 commit comments