*/
#include "folly/File.h"
+#include "folly/Format.h"
#include "folly/ScopeGuard.h"
#include <system_error>
, ownsFd_(false) {
if (fd_ < 0) {
- throw std::system_error(errno, std::system_category(), "open() failed");
+ throw std::system_error(errno, std::system_category(),
+ folly::format("open(\"{}\", {:#o}, 0{:#o}) failed",
+ name, flags, mode).str());
}
ownsFd_ = true;
}
::close(p[0]);
}
+#define EXPECT_CONTAINS(haystack, needle) \
+ EXPECT_NE(::std::string::npos, ::folly::StringPiece(haystack).find(needle)) \
+ << "Haystack: '" << haystack << "'\nNeedle: '" << needle << "'";
+
+TEST(File, UsefulError) {
+ try {
+ File("does_not_exist.txt", 0, 0666);
+ } catch (const std::runtime_error& e) {
+ EXPECT_CONTAINS(e.what(), "does_not_exist.txt");
+ EXPECT_CONTAINS(e.what(), "0666");
+ }
+}