Merge pull request #2155 from ethereum/guard-readcallback

Guard ReadFileCallback exceptions
This commit is contained in:
chriseth 2017-04-24 12:28:03 +02:00 committed by GitHub
commit a9f4215720
3 changed files with 36 additions and 23 deletions

View File

@ -79,7 +79,8 @@ class CompilerStack: boost::noncopyable
{ {
public: public:
/// Creates a new compiler stack. /// Creates a new compiler stack.
/// @param _readFile callback to used to read files for import statements. Should return /// @param _readFile callback to used to read files for import statements. Must return
/// and must not emit exceptions.
explicit CompilerStack(ReadFile::Callback const& _readFile = ReadFile::Callback()); explicit CompilerStack(ReadFile::Callback const& _readFile = ReadFile::Callback());
/// Sets path remappings in the format "context:prefix=target" /// Sets path remappings in the format "context:prefix=target"

View File

@ -38,7 +38,8 @@ class StandardCompiler: boost::noncopyable
{ {
public: public:
/// Creates a new StandardCompiler. /// Creates a new StandardCompiler.
/// @param _readFile callback to used to read files for import statements. Should return /// @param _readFile callback to used to read files for import statements. Must return
/// and must not emit exceptions.
StandardCompiler(ReadFile::Callback const& _readFile = ReadFile::Callback()) StandardCompiler(ReadFile::Callback const& _readFile = ReadFile::Callback())
: m_compilerStack(_readFile), m_readFile(_readFile) : m_compilerStack(_readFile), m_readFile(_readFile)
{ {

View File

@ -617,6 +617,8 @@ Allowed options)",
bool CommandLineInterface::processInput() bool CommandLineInterface::processInput()
{ {
ReadFile::Callback fileReader = [this](string const& _path) ReadFile::Callback fileReader = [this](string const& _path)
{
try
{ {
auto path = boost::filesystem::path(_path); auto path = boost::filesystem::path(_path);
auto canonicalPath = boost::filesystem::canonical(path); auto canonicalPath = boost::filesystem::canonical(path);
@ -645,6 +647,15 @@ bool CommandLineInterface::processInput()
m_sourceCodes[path.string()] = contents; m_sourceCodes[path.string()] = contents;
return ReadFile::Result{true, contents}; return ReadFile::Result{true, contents};
} }
}
catch (Exception const& _exception)
{
return ReadFile::Result{false, "Exception in read callback: " + boost::diagnostic_information(_exception)};
}
catch (...)
{
return ReadFile::Result{false, "Unknown exception in read callback."};
}
}; };
if (m_args.count(g_argAllowPaths)) if (m_args.count(g_argAllowPaths))