Skip to content

Commit 6c74987

Browse files
committed
Replace runtime_error in soltest with ConfigException/assertions where appropriate
1 parent 58795c7 commit 6c74987

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

test/Common.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <libyul/backends/evm/EVMDialect.h>
2525

2626
#include <libsolutil/Assertions.h>
27+
#include <libsolutil/Exceptions.h>
2728
#include <libsolutil/StringUtils.h>
2829

2930
#include <boost/algorithm/string.hpp>
@@ -185,8 +186,7 @@ bool CommonOptions::parse(int argc, char const* const* argv)
185186
{
186187
// Request as uint64_t, since uint8_t will be parsed as character by boost.
187188
uint64_t eofVersion = arguments["eof-version"].as<uint64_t>();
188-
if (eofVersion != 1)
189-
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid EOF version: " + std::to_string(eofVersion)));
189+
solRequire(eofVersion == 1, ConfigException, "Invalid EOF version: " + std::to_string(eofVersion));
190190
m_eofVersion = 1;
191191
}
192192

@@ -198,11 +198,7 @@ bool CommonOptions::parse(int argc, char const* const* argv)
198198
(parsedOption.original_tokens.size() == 1 && parsedOption.original_tokens.front().empty())
199199
)
200200
continue; // ignore empty options
201-
std::stringstream errorMessage;
202-
errorMessage << "Unrecognized option: ";
203-
for (auto const& token: parsedOption.original_tokens)
204-
errorMessage << token;
205-
BOOST_THROW_EXCEPTION(std::runtime_error(errorMessage.str()));
201+
solThrow(ConfigException, "Unrecognized option: " + util::joinHumanReadable(parsedOption.original_tokens, ""));
206202
}
207203
}
208204
catch (po::error const& exception)
@@ -262,8 +258,7 @@ langutil::EVMVersion CommonOptions::evmVersion() const
262258
if (!m_evmVersionString.empty())
263259
{
264260
auto version = langutil::EVMVersion::fromString(m_evmVersionString);
265-
if (!version)
266-
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid EVM version: " + m_evmVersionString));
261+
solRequire(version, ConfigException, "Invalid EVM version: " + m_evmVersionString);
267262
return *version;
268263
}
269264
else
@@ -279,7 +274,7 @@ yul::EVMDialect const& CommonOptions::evmDialect() const
279274
CommonOptions const& CommonOptions::get()
280275
{
281276
if (!m_singleton)
282-
BOOST_THROW_EXCEPTION(std::runtime_error("Options not yet constructed!"));
277+
soltestAssert(false, "Options not yet constructed!");
283278

284279
return *m_singleton;
285280
}

test/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct CommonOptions
7676
virtual void addOptions();
7777
// @returns true if the program should continue, false if it should exit immediately without
7878
// reporting an error.
79-
// Throws ConfigException or std::runtime_error if parsing fails.
79+
// Throws ConfigException if parsing fails.
8080
virtual bool parse(int argc, char const* const* argv);
8181
// Throws a ConfigException on error
8282
virtual void validate() const;

test/EVMHost.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#endif
3030

3131
#include <test/EVMHost.h>
32+
33+
#include <test/Common.h>
3234
#include <test/libsolidity/util/SoltestErrors.h>
3335

3436
#if defined(__GNUC__) && !defined(__clang__) // GCC-specific pragma
@@ -91,8 +93,7 @@ bool EVMHost::checkVmPaths(std::vector<boost::filesystem::path> const& _vmPaths)
9193

9294
if (vm.has_capability(EVMC_CAPABILITY_EVM1))
9395
{
94-
if (evmVmFound)
95-
BOOST_THROW_EXCEPTION(std::runtime_error("Multiple evm1 evmc vms defined. Please only define one evm1 evmc vm."));
96+
solRequire(!evmVmFound, ConfigException, "Multiple evm1 evmc vms defined. Please only define one evm1 evmc vm.");
9697
evmVmFound = true;
9798
}
9899
}

0 commit comments

Comments
 (0)