mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-01 19:41:48 +00:00
Update error handling
This commit is contained in:
parent
7fe4e1c9f5
commit
81f25dc180
|
@ -23,14 +23,15 @@ using namespace spdlog;
|
||||||
using namespace scsi_defs;
|
using namespace scsi_defs;
|
||||||
using namespace piscsi_interface;
|
using namespace piscsi_interface;
|
||||||
|
|
||||||
string ScsiExecutor::Execute(const string& filename, bool binary)
|
bool ScsiExecutor::Execute(const string& filename, bool binary, string& result)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
if (!binary) {
|
if (!binary) {
|
||||||
ifstream in(filename);
|
ifstream in(filename);
|
||||||
if (in.fail()) {
|
if (in.fail()) {
|
||||||
return "Error opening JSON input file '" + filename + "'";
|
result = "Error opening JSON input file '" + filename + "'";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stringstream buf;
|
stringstream buf;
|
||||||
|
@ -42,7 +43,8 @@ string ScsiExecutor::Execute(const string& filename, bool binary)
|
||||||
else {
|
else {
|
||||||
ifstream in(filename, ios::binary);
|
ifstream in(filename, ios::binary);
|
||||||
if (in.fail()) {
|
if (in.fail()) {
|
||||||
return "Error opening binary input file '" + filename + "'";
|
result = "Error opening binary input file '" + filename + "'";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<char> b(file_size(filename));
|
vector<char> b(file_size(filename));
|
||||||
|
@ -63,15 +65,16 @@ string ScsiExecutor::Execute(const string& filename, bool binary)
|
||||||
|
|
||||||
if (!binary) {
|
if (!binary) {
|
||||||
const string json((const char*) buffer.data(), length);
|
const string json((const char*) buffer.data(), length);
|
||||||
return json;
|
result = json;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PbResult result;
|
PbResult r;
|
||||||
if (!result.ParseFromArray(buffer.data(), length)) {
|
if (!r.ParseFromArray(buffer.data(), length)) {
|
||||||
assert(false);
|
result = "Error parsing binary protobuf data";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
string json;
|
google::protobuf::util::MessageToJsonString(r, &result);
|
||||||
google::protobuf::util::MessageToJsonString(result, &json);
|
|
||||||
return json;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
}
|
}
|
||||||
~ScsiExecutor() = default;
|
~ScsiExecutor() = default;
|
||||||
|
|
||||||
string Execute(const string&, bool);
|
bool Execute(const string&, bool, string&);
|
||||||
|
|
||||||
void SetTarget(int id, int lun)
|
void SetTarget(int id, int lun)
|
||||||
{
|
{
|
||||||
|
|
|
@ -156,11 +156,18 @@ int ScsiExec::run(span<char*> args, bool in_process)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << scsi_executor->Execute(filename, binary) << "\n" << flush;
|
string result;
|
||||||
|
const bool status = scsi_executor->Execute(filename, binary, result);
|
||||||
|
if (status) {
|
||||||
|
cout << result << '\n' << flush;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cerr << result << endl;
|
||||||
|
}
|
||||||
|
|
||||||
CleanUp();
|
CleanUp();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return status ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScsiExec::SetLogLevel() const
|
bool ScsiExec::SetLogLevel() const
|
||||||
|
|
Loading…
Reference in New Issue
Block a user