From f05a07d0ccce869f59b2cb921a52a6f539d84c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 28 Feb 2020 03:48:20 +0100 Subject: [PATCH] [yul-phaser] Create BadInput exception hierarchy and make exceptions used by Phaser more specific --- tools/yulPhaser/Exceptions.h | 5 ++++- tools/yulPhaser/Phaser.cpp | 7 ++----- tools/yulPhaser/main.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/yulPhaser/Exceptions.h b/tools/yulPhaser/Exceptions.h index ae75d19ef..1f675a9ef 100644 --- a/tools/yulPhaser/Exceptions.h +++ b/tools/yulPhaser/Exceptions.h @@ -22,6 +22,9 @@ 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 {}; } diff --git a/tools/yulPhaser/Phaser.cpp b/tools/yulPhaser/Phaser.cpp index 87bbb0eba..4c2aff071 100644 --- a/tools/yulPhaser/Phaser.cpp +++ b/tools/yulPhaser/Phaser.cpp @@ -136,7 +136,7 @@ Program ProgramFactory::build(Options const& _options) 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); return CharStream(sourceCode, _sourcePath); @@ -216,10 +216,7 @@ Phaser::CommandLineParsingResult Phaser::parseCommandLine(int _argc, char** _arg } if (arguments.count("input-file") == 0) - { - cerr << "Missing argument: input-file." << endl; - return {1, move(arguments)}; - } + assertThrow(false, NoInputFiles, "Missing argument: input-file."); return {0, arguments}; } diff --git a/tools/yulPhaser/main.cpp b/tools/yulPhaser/main.cpp index 1cfd310b7..a567e355a 100644 --- a/tools/yulPhaser/main.cpp +++ b/tools/yulPhaser/main.cpp @@ -36,10 +36,10 @@ int main(int argc, char** argv) std::cerr << "ERROR: " << exception.what() << std::endl; 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. - // Handle it and exit. + // Bad input data. Syntax errors in the input program, semantic errors in command-line + // parameters, etc. std::cerr << std::endl; std::cerr << "ERROR: " << exception.what() << std::endl;