diff --git a/src/core/desktopfile/desktopfile.cpp b/src/core/desktopfile/desktopfile.cpp index f40262b..d485d12 100644 --- a/src/core/desktopfile/desktopfile.cpp +++ b/src/core/desktopfile/desktopfile.cpp @@ -1,4 +1,5 @@ // local headers +#include "linuxdeploy/core/desktopfile/exceptions.h" #include "linuxdeploy/core/desktopfile/desktopfile.h" #include "linuxdeploy/core/log.h" #include "desktopfilereader.h" @@ -34,10 +35,15 @@ namespace linuxdeploy { DesktopFile::DesktopFile() : d(std::make_shared()) {} DesktopFile::DesktopFile(const bf::path& path) : DesktopFile() { - if (bf::exists(path)) { - // will throw exceptions in case of issues - read(path); + // if the file doesn't exist, an exception shall be thrown + // otherwise, a user cannot know for sure whether a file was actually read (would need to check this + // manually beforehand + if (!bf::exists(path)) { + throw IOError("Could not find file " + path.string()); } + + // will throw exceptions in case of issues + read(path); }; DesktopFile::DesktopFile(std::istream& is) : DesktopFile() { diff --git a/tests/core/desktopfile/test_desktopfile.cpp b/tests/core/desktopfile/test_desktopfile.cpp index 01d4491..a49f493 100644 --- a/tests/core/desktopfile/test_desktopfile.cpp +++ b/tests/core/desktopfile/test_desktopfile.cpp @@ -4,6 +4,7 @@ // local headers #include "linuxdeploy/core/desktopfile/desktopfile.h" +#include "linuxdeploy/core/desktopfile/exceptions.h" #include "../../src/core/desktopfile/desktopfilereader.h" using boost::bad_lexical_cast; @@ -66,8 +67,7 @@ TEST_F(DesktopFileFixture, testDefaultConstructor) { } TEST_F(DesktopFileFixture, testPathConstructor) { - DesktopFile nonExistingPath("/a/b/c/d/e/f/g/h/1/2/3/4/5/6/7/8"); - EXPECT_TRUE(nonExistingPath.isEmpty()); + ASSERT_THROW(DesktopFile nonExistingPath("/a/b/c/d/e/f/g/h/1/2/3/4/5/6/7/8"), IOError); DesktopFile emptyFile("/dev/null"); EXPECT_TRUE(emptyFile.isEmpty());