Merge pull request #11579 from ethereum/better-errors-about-bad-paths-in-tests-with-external-sources

Better errors about bad paths in tests with external sources
This commit is contained in:
chriseth
2021-06-30 11:56:47 +02:00
committed by GitHub
12 changed files with 210 additions and 2 deletions
+8
View File
@@ -43,9 +43,17 @@ namespace
template <typename T>
inline T readFile(std::string const& _file)
{
assertThrow(boost::filesystem::exists(_file), FileNotFound, _file);
// ifstream does not always fail when the path leads to a directory. Instead it might succeed
// with tellg() returning a nonsensical value so that std::length_error gets raised in resize().
assertThrow(boost::filesystem::is_regular_file(_file), NotAFile, _file);
T ret;
size_t const c_elementSize = sizeof(typename T::value_type);
std::ifstream is(_file, std::ifstream::binary);
// Technically, this can still fail even though we checked above because FS content can change at any time.
assertThrow(is, FileNotFound, _file);
// get length of file:
+1
View File
@@ -33,6 +33,7 @@ namespace solidity::util
/// Retrieve and returns the contents of the given file as a std::string.
/// If the file doesn't exist, it will throw a FileNotFound exception.
/// If the file exists but is not a regular file, it will throw NotAFile exception.
/// If the file is empty, returns an empty string.
std::string readFileAsString(std::string const& _file);
+1
View File
@@ -49,6 +49,7 @@ DEV_SIMPLE_EXCEPTION(InvalidAddress);
DEV_SIMPLE_EXCEPTION(BadHexCharacter);
DEV_SIMPLE_EXCEPTION(BadHexCase);
DEV_SIMPLE_EXCEPTION(FileNotFound);
DEV_SIMPLE_EXCEPTION(NotAFile);
DEV_SIMPLE_EXCEPTION(DataTooLong);
DEV_SIMPLE_EXCEPTION(StringTooLong);