[yul-phaser] Create BadInput exception hierarchy and make exceptions used by Phaser more specific

This commit is contained in:
Kamil Śliwak 2020-02-28 03:48:20 +01:00
parent 53803801f7
commit f05a07d0cc
3 changed files with 9 additions and 9 deletions

View File

@ -22,6 +22,9 @@
namespace solidity::phaser namespace solidity::phaser
{ {
struct InvalidProgram: virtual util::Exception {}; struct BadInput: virtual util::Exception {};
struct InvalidProgram: virtual BadInput {};
struct NoInputFiles: virtual BadInput {};
struct MissingFile: virtual BadInput {};
} }

View File

@ -136,7 +136,7 @@ Program ProgramFactory::build(Options const& _options)
CharStream ProgramFactory::loadSource(string const& _sourcePath) CharStream ProgramFactory::loadSource(string const& _sourcePath)
{ {
assertThrow(boost::filesystem::exists(_sourcePath), InvalidProgram, "Source file does not exist"); assertThrow(boost::filesystem::exists(_sourcePath), MissingFile, "Source file does not exist: " + _sourcePath);
string sourceCode = readFileAsString(_sourcePath); string sourceCode = readFileAsString(_sourcePath);
return CharStream(sourceCode, _sourcePath); return CharStream(sourceCode, _sourcePath);
@ -216,10 +216,7 @@ Phaser::CommandLineParsingResult Phaser::parseCommandLine(int _argc, char** _arg
} }
if (arguments.count("input-file") == 0) if (arguments.count("input-file") == 0)
{ assertThrow(false, NoInputFiles, "Missing argument: input-file.");
cerr << "Missing argument: input-file." << endl;
return {1, move(arguments)};
}
return {0, arguments}; return {0, arguments};
} }

View File

@ -36,10 +36,10 @@ int main(int argc, char** argv)
std::cerr << "ERROR: " << exception.what() << std::endl; std::cerr << "ERROR: " << exception.what() << std::endl;
return 1; return 1;
} }
catch (solidity::phaser::InvalidProgram const& exception) catch (solidity::phaser::BadInput const& exception)
{ {
// Error in the input data. One of the provided programs contains errors and could not be loaded. // Bad input data. Syntax errors in the input program, semantic errors in command-line
// Handle it and exit. // parameters, etc.
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "ERROR: " << exception.what() << std::endl; std::cerr << "ERROR: " << exception.what() << std::endl;