fix exit status: several executables reported success (0) on failure or vice versa
Build and Deploy Documentation / build-and-deploy (push) Successful in 23s
Build and Deploy Documentation / build-and-deploy (push) Successful in 23s
Two bug patterns fixed across src/*.cpp: - musrfit, musrview, any2many, addRun, musrFT, musrt0: a local success/ok/isGood flag was tracked and an error printed, but the function fell through to an unconditional `return PMUSR_SUCCESS;` at the end instead of propagating the failure. - msr2data, msr2msr: the success path returned a nonzero code (1) instead of 0. Also propagate previously-ignored return codes to the process exit status in dump_header (format-dispatch functions), musrRootValidation (schema validation / consistency checks), and write_musrRoot_runHeader (FillFolder failure).
This commit is contained in:
@@ -797,5 +797,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (!isGood)
|
||||
return PMUSR_DATA_FILE_READ_ERROR;
|
||||
|
||||
return PMUSR_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -533,6 +533,7 @@ int main(int argc, char *argv[])
|
||||
bool success = dataHandler->IsAllDataAvailable();
|
||||
if (!success) {
|
||||
std::cerr << std::endl << ">> any2many **ERROR** Couldn't read all data files, will quit ..." << std::endl;
|
||||
return PMUSR_DATA_FILE_READ_ERROR;
|
||||
}
|
||||
|
||||
return PMUSR_SUCCESS;
|
||||
|
||||
+8
-6
@@ -1083,21 +1083,23 @@ int main(int argc, char *argv[])
|
||||
|
||||
boost::to_lower(fileFormat);
|
||||
|
||||
int status = 0;
|
||||
if (boost::iequals(fileFormat, "MusrRoot") || boost::iequals(fileFormat, "ROOT")) {
|
||||
dump_header_root(pathFln, summary, counts);
|
||||
status = dump_header_root(pathFln, summary, counts);
|
||||
} else if (boost::iequals(fileFormat, "NeXus")) {
|
||||
#ifdef PNEXUS_ENABLED
|
||||
dump_header_nexus(pathFln, counts);
|
||||
status = dump_header_nexus(pathFln, counts);
|
||||
#else
|
||||
std::cout << std::endl << "Sorry, NeXus is not enabled, hence I cannot help you." << std::endl;
|
||||
status = 1;
|
||||
#endif
|
||||
} else if (boost::iequals(fileFormat, "PSI-BIN") || boost::iequals(fileFormat, "PSI-MDU")) {
|
||||
dump_header_psi_bin(pathFln, fileFormat, counts);
|
||||
status = dump_header_psi_bin(pathFln, fileFormat, counts);
|
||||
} else if (boost::iequals(fileFormat, "MUD")) {
|
||||
dump_header_mud(pathFln, counts);
|
||||
status = dump_header_mud(pathFln, counts);
|
||||
} else if (boost::iequals(fileFormat, "WKM")) {
|
||||
dump_header_wkm(pathFln);
|
||||
status = dump_header_wkm(pathFln);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return status;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1005,5 +1005,5 @@ int main(int argc, char *argv[])
|
||||
|
||||
std::cout << std::endl << ">> msr2data: done ..." << std::endl;
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-2
@@ -676,12 +676,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
// check if conversion seems to be OK
|
||||
if (!success) {
|
||||
std::cerr << std::endl << "**ERROR** conversion of " << argv[1] << " failed, removing " << argv[2] << "." << std::endl;
|
||||
std::error_code ec;
|
||||
std::filesystem::remove_all(std::filesystem::path(argv[2]), ec);
|
||||
if (ec) {
|
||||
std::cerr << "**ERROR** couldn't remove " << argv[2] << ": " << ec.message() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (theoryTag != -1) {
|
||||
@@ -690,5 +691,5 @@ int main(int argc, char *argv[])
|
||||
|
||||
std::cout << std::endl << "done ..." << std::endl;
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+4
-1
@@ -1449,6 +1449,8 @@ Int_t main(Int_t argc, Char_t *argv[])
|
||||
|
||||
std::unique_ptr<PFourierCanvas> fourierCanvas;
|
||||
|
||||
Int_t result = PMUSR_SUCCESS;
|
||||
|
||||
// if Fourier dumped if whished do it now
|
||||
if (startupParam.dumpFln.Length() > 0) {
|
||||
musrFT_dumpData(startupParam.dumpFln, fourier, startupParam.fourierRange[0], startupParam.fourierRange[1]);
|
||||
@@ -1495,6 +1497,7 @@ Int_t main(Int_t argc, Char_t *argv[])
|
||||
std::cerr << std::endl << ">> musrFT **SEVERE ERROR** Couldn't invoke all necessary objects, will quit.";
|
||||
std::cerr << std::endl;
|
||||
ok = false;
|
||||
result = PMUSR_MSR_RUN_ERROR;
|
||||
} else {
|
||||
// connect signal/slot
|
||||
TQObject::Connect("TCanvas", "Closed()", "PFourierCanvas", fourierCanvas.get(), "LastCanvasClosed()");
|
||||
@@ -1524,5 +1527,5 @@ Int_t main(Int_t argc, Char_t *argv[])
|
||||
app.Run();
|
||||
}
|
||||
|
||||
return PMUSR_SUCCESS;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -680,10 +680,13 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool valid = true;
|
||||
|
||||
if (is_valid(doc, argv[2])) {
|
||||
std::cout << std::endl << "xml-file " << argv[1] << " validates against xml-schema " << argv[2] << std::endl << std::endl;
|
||||
} else {
|
||||
std::cerr << std::endl << "**ERROR** xml-file " << argv[1] << " fails to validate against xml-schema " << argv[2] << std::endl << std::endl;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
// do some further consistency checks
|
||||
@@ -692,6 +695,7 @@ int main(int argc, char *argv[])
|
||||
std::cerr << std::endl << " with the header; found " << dump.GetNoOfDecayHistos() << " histograms in the DecayAnaModule,";
|
||||
std::cerr << std::endl << " but in the header: No of Histos = " << dump.GetNoOfHistos() << "; # RedGreen Offsets = " << dump.GetNoOfRedGreenOffsets();
|
||||
std::cerr << std::endl << std::endl;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (dump.GetNoOfDecayHistos() != dump.GetNoOfDetectors()) {
|
||||
@@ -700,7 +704,11 @@ int main(int argc, char *argv[])
|
||||
std::cerr << std::endl << " Found " << dump.GetNoOfDecayHistos() << " histograms in the DecayAnaModule,";
|
||||
std::cerr << std::endl << " but " << dump.GetNoOfDetectors() << " number of Detector entries.";
|
||||
std::cerr << std::endl << std::endl;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+9
-2
@@ -700,9 +700,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
dataHandler->ReadData();
|
||||
|
||||
int result = PMUSR_SUCCESS;
|
||||
|
||||
bool success = dataHandler->IsAllDataAvailable();
|
||||
if (!success) {
|
||||
std::cerr << std::endl << ">> musrfit **ERROR** Couldn't read all data files, will quit ..." << std::endl;
|
||||
result = PMUSR_DATA_FILE_READ_ERROR;
|
||||
}
|
||||
|
||||
// if present, replace the run title of the <msr-file> with the run title of the FIRST run in the run block of the msr-file
|
||||
@@ -711,12 +714,14 @@ int main(int argc, char *argv[])
|
||||
if (rl->empty()) {
|
||||
success = false;
|
||||
std::cerr << std::endl << ">> musrfit **ERROR** no run list present." << std::endl;
|
||||
result = PMUSR_MSR_RUN_ERROR;
|
||||
}
|
||||
if (success) {
|
||||
TString *name = rl->at(0).GetRunName();
|
||||
if (name == nullptr) {
|
||||
std::cerr << std::endl << ">> musrfit **ERROR** to obtain run list name." << std::endl;
|
||||
success = false;
|
||||
result = PMUSR_MSR_RUN_ERROR;
|
||||
}
|
||||
PRawRunData *rrd = nullptr;
|
||||
if (success) {
|
||||
@@ -724,6 +729,7 @@ int main(int argc, char *argv[])
|
||||
if (rrd == nullptr) {
|
||||
std::cerr << std::endl << ">> musrfit **ERROR** no raw run data avaliable." << std::endl;
|
||||
success = false;
|
||||
result = PMUSR_MSR_RUN_ERROR;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
@@ -736,13 +742,14 @@ int main(int argc, char *argv[])
|
||||
// generate the necessary fit histogramms for the fit
|
||||
std::unique_ptr<PRunListCollection> runListCollection;
|
||||
if (success) {
|
||||
// feed all the necessary histogramms for the fit
|
||||
// feed all the necessary histogramms for the fit
|
||||
runListCollection = std::make_unique<PRunListCollection>(msrHandler.get(), dataHandler.get());
|
||||
for (unsigned int i=0; i < msrHandler->GetMsrRunList()->size(); i++) {
|
||||
success = runListCollection->Add(i, kFit);
|
||||
if (!success) {
|
||||
std::cout << std::endl << ">> musrfit **ERROR** Couldn't handle run no " << i+1 << ": ";
|
||||
std::cout << (*msrHandler->GetMsrRunList())[i].GetRunName()->Data();
|
||||
result = PMUSR_MSR_RUN_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -840,7 +847,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
std::cout << std::endl << "done ..." << std::endl;
|
||||
|
||||
return PMUSR_SUCCESS;
|
||||
return result;
|
||||
}
|
||||
|
||||
// end ---------------------------------------------------------------------
|
||||
|
||||
@@ -312,6 +312,8 @@ Int_t main(Int_t argc, Char_t *argv[])
|
||||
}
|
||||
msrHandler->CopyMsrStatisticBlock(); // just copy the statistics block since no fit is performed
|
||||
|
||||
Int_t result = PMUSR_SUCCESS;
|
||||
|
||||
// check if the fittype is not NonMusr
|
||||
PMsrRunList *runList = msrHandler->GetMsrRunList();
|
||||
for (UInt_t i=0; i<runList->size(); i++) {
|
||||
@@ -322,6 +324,7 @@ Int_t main(Int_t argc, Char_t *argv[])
|
||||
if (fitType == MSR_FITTYPE_NON_MUSR) {
|
||||
std::cout << std::endl << ">> musrt0 **ERROR** t0 setting for NonMusr fit type doesn't make any sense, will quit ..." << std::endl;
|
||||
success = false;
|
||||
result = PMUSR_UNSUPPORTED_FEATURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -339,6 +342,7 @@ Int_t main(Int_t argc, Char_t *argv[])
|
||||
success = dataHandler->IsAllDataAvailable();
|
||||
if (!success) {
|
||||
std::cout << std::endl << ">> musrt0 **ERROR** Couldn't read all data files, will quit ..." << std::endl;
|
||||
result = PMUSR_DATA_FILE_READ_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1160,6 +1164,9 @@ Int_t main(Int_t argc, Char_t *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
return result;
|
||||
|
||||
// write msr-file
|
||||
msrHandler->WriteMsrLogFile(false);
|
||||
|
||||
|
||||
@@ -369,6 +369,7 @@ int main(int argc, char *argv[])
|
||||
if (show_errMsgBox)
|
||||
musrview_error_msg(errMsg.str());
|
||||
ok = false;
|
||||
result = PMUSR_MSR_RUN_ERROR;
|
||||
break;
|
||||
}
|
||||
if (!musrCanvas->IsValid()) {
|
||||
@@ -377,6 +378,7 @@ int main(int argc, char *argv[])
|
||||
if (show_errMsgBox)
|
||||
musrview_error_msg(errMsg.str());
|
||||
ok = false;
|
||||
result = PMUSR_MSR_RUN_ERROR;
|
||||
delete musrCanvas;
|
||||
break;
|
||||
}
|
||||
@@ -393,6 +395,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!musrCanvas->IsValid()) { // something went wrong
|
||||
ok = false;
|
||||
result = PMUSR_MSR_RUN_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -245,8 +245,11 @@ int main(int argc, char *argv[])
|
||||
// root file header related things
|
||||
TFolder *runHeader = new TFolder("RunHeader", "MusrRoot Run Header Info");
|
||||
|
||||
if (header->FillFolder(runHeader)) {
|
||||
bool success = header->FillFolder(runHeader);
|
||||
if (success) {
|
||||
runHeader->Write();
|
||||
} else {
|
||||
std::cerr << std::endl << "**ERROR** couldn't fill the MusrRoot run header folder." << std::endl;
|
||||
}
|
||||
|
||||
f->Close();
|
||||
@@ -255,5 +258,8 @@ int main(int argc, char *argv[])
|
||||
delete f;
|
||||
delete header;
|
||||
|
||||
if (!success)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user