From 0aed5664efff7ff5da4733df6806c84594d202e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 30 May 2017 10:57:31 +0200 Subject: [PATCH] Let openFile throw on failure instead of returning an invalid stream. --- source/vibe/core/file.d | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 6b0cc99..3ef2295 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -37,7 +37,9 @@ version(Posix){ */ FileStream openFile(Path path, FileMode mode = FileMode.read) { - return FileStream(eventDriver.files.open(path.toNativeString(), cast(FileOpenMode)mode), path, mode); + auto fil = eventDriver.files.open(path.toNativeString(), cast(FileOpenMode)mode); + enforce(fil != FileFD.invalid, "Failed to open file '"~path.toNativeString~"'"); + return FileStream(fil, path, mode); } /// ditto FileStream openFile(string path, FileMode mode = FileMode.read) @@ -393,8 +395,9 @@ struct FileStream { CTX* m_ctx; } - this(FileFD fd, Path path, FileMode mode) + private this(FileFD fd, Path path, FileMode mode) { + assert(fd != FileFD.invalid, "Constructing FileStream from invalid file descriptor."); m_fd = fd; m_ctx = new CTX; // TODO: use FD custom storage m_ctx.path = path;