From c05ebd7ea80dcbd850ea5833d492ef1a5e3a07d7 Mon Sep 17 00:00:00 2001
From: Mook <mook@users.noreply.github.com>
Date: Fri, 30 Oct 2015 20:25:49 -0700
Subject: [PATCH] Filesystem: Actually throw ENOENT for missing files

---
 src/filesystem.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/filesystem.cpp b/src/filesystem.cpp
index fe5d403..c2a8e8d 100644
--- a/src/filesystem.cpp
+++ b/src/filesystem.cpp
@@ -650,7 +650,20 @@ void FileSystem::openReadRaw(SDL_RWops &ops,
                              bool freeOnClose)
 {
 	PHYSFS_File *handle = PHYSFS_openRead(filename);
-	assert(handle);
+
+	if (!handle)
+	{
+		PHYSFS_ErrorCode error = PHYSFS_getLastErrorCode();
+		switch (error)
+		{
+		case PHYSFS_ERR_NOT_FOUND:
+		case PHYSFS_ERR_NOT_A_FILE:
+			throw Exception(Exception::NoFileError, "%s", filename);
+		default:
+			throw Exception(Exception::PHYSFSError,
+			                "PhysFS: %s", PHYSFS_getErrorByCode(error));
+		}
+	}
 
 	initReadOps(handle, ops, freeOnClose);
 }