Skip to content

Commit c05ebd7

Browse files
committed
Filesystem: Actually throw ENOENT for missing files
1 parent 7bf6eca commit c05ebd7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/filesystem.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,20 @@ void FileSystem::openReadRaw(SDL_RWops &ops,
650650
bool freeOnClose)
651651
{
652652
PHYSFS_File *handle = PHYSFS_openRead(filename);
653-
assert(handle);
653+
654+
if (!handle)
655+
{
656+
PHYSFS_ErrorCode error = PHYSFS_getLastErrorCode();
657+
switch (error)
658+
{
659+
case PHYSFS_ERR_NOT_FOUND:
660+
case PHYSFS_ERR_NOT_A_FILE:
661+
throw Exception(Exception::NoFileError, "%s", filename);
662+
default:
663+
throw Exception(Exception::PHYSFSError,
664+
"PhysFS: %s", PHYSFS_getErrorByCode(error));
665+
}
666+
}
654667

655668
initReadOps(handle, ops, freeOnClose);
656669
}

0 commit comments

Comments
 (0)