diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-06-15 15:45:45 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-06-15 22:19:00 +0200 |
commit | 97923e3d26d2fb5a6be6c00b8d8d6a085cf71b8e (patch) | |
tree | b535881c51659cc9d79f3759e97e440f00adf3ef /deno2/file_util.cc | |
parent | b2694ecbd85a5a32803e24f1d6c9020173408646 (diff) |
Fix error handling in deno::ReadFileToString
Starts a unit test for it, and adds to mock_runtime_test.
Diffstat (limited to 'deno2/file_util.cc')
-rw-r--r-- | deno2/file_util.cc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/deno2/file_util.cc b/deno2/file_util.cc index e2c1b3049..ece14e9b1 100644 --- a/deno2/file_util.cc +++ b/deno2/file_util.cc @@ -11,8 +11,11 @@ namespace deno { bool ReadFileToString(const char* fn, std::string* contents) { std::ifstream file(fn, std::ios::binary); + if (file.fail()) { + return false; + } contents->assign(std::istreambuf_iterator<char>{file}, {}); - return !file.bad(); + return !file.fail(); } class StartupDataCppWriter { |