Merge pull request #10199 from ethereum/readfile

[CLI] Improve error handling of missing/unwriteable files
This commit is contained in:
chriseth
2020-11-10 13:50:40 +01:00
committed by GitHub
10 changed files with 55 additions and 9 deletions
@@ -0,0 +1 @@
--standard-json
@@ -0,0 +1 @@
File not found: standard_file_not_found/input.sol
@@ -0,0 +1 @@
1
+12 -1
View File
@@ -20,6 +20,7 @@
*/
#include <libsolutil/CommonIO.h>
#include <libsolutil/Exceptions.h>
#include <liblangutil/ErrorReporter.h>
#include <liblangutil/Scanner.h>
#include <libyul/AsmAnalysis.h>
@@ -243,8 +244,18 @@ Allowed options)",
}
string input;
try
{
input = readFileAsString(arguments["input-file"].as<string>());
}
catch (FileNotFound const& _exception)
{
cerr << "File not found:" << _exception.comment() << endl;
return 1;
}
if (arguments.count("input-file"))
YulOpti{}.runInteractive(readFileAsString(arguments["input-file"].as<string>()));
YulOpti{}.runInteractive(input);
else
cout << options;
+12 -2
View File
@@ -35,6 +35,7 @@
#include <libsolutil/CommonIO.h>
#include <libsolutil/CommonData.h>
#include <libsolutil/Exceptions.h>
#include <boost/program_options.hpp>
@@ -137,10 +138,19 @@ Allowed options)",
else
{
string input;
if (arguments.count("input-file"))
for (string path: arguments["input-file"].as<vector<string>>())
input += readFileAsString(path);
{
try
{
input += readFileAsString(path);
}
catch (FileNotFound const&)
{
cerr << "File not found: " << path << endl;
return 1;
}
}
else
input = readStandardInput();