Skip to content

Commit

Permalink
Fix segfault encountered when importing logs (#1702)
Browse files Browse the repository at this point in the history
* Fix segfault when a study is invalid

* Re-throw loading exceptions in case of failure

* Formatting

* Rename
  • Loading branch information
flomnes authored Oct 13, 2023
1 parent 50891e7 commit 12c3abb
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions src/solver/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,38 +305,53 @@ void Application::readDataForTheStudy(Data::StudyLoadOptions& options)
// Load the study from a folder
Benchmarking::Timer timer;

if (study.loadFromFolder(pSettings.studyFolder, options) && !study.gotFatalError)
std::exception_ptr loadingException;
try
{
logs.info() << "The study is loaded.";
logs.info() << LOG_UI_DISPLAY_MESSAGES_OFF;
}
if (study.loadFromFolder(pSettings.studyFolder, options) && !study.gotFatalError)
{
logs.info() << "The study is loaded.";
logs.info() << LOG_UI_DISPLAY_MESSAGES_OFF;
}

timer.stop();
pDurationCollector.addDuration("study_loading", timer.get_duration());
timer.stop();
pDurationCollector.addDuration("study_loading", timer.get_duration());

if (study.gotFatalError)
throw Error::ReadingStudy();
if (study.gotFatalError)
throw Error::ReadingStudy();

if (study.areas.empty())
{
throw Error::NoAreas();
}
if (study.areas.empty())
{
throw Error::NoAreas();
}

// no output ?
study.parameters.noOutput = pSettings.noOutput;
// no output ?
study.parameters.noOutput = pSettings.noOutput;

if (pSettings.forceZipOutput)
if (pSettings.forceZipOutput)
{
pParameters->resultFormat = Antares::Data::zipArchive;
}
}
catch (...)
{
pParameters->resultFormat = Antares::Data::zipArchive;
loadingException = std::current_exception();
}

// This settings can only be enabled from the solver
// Prepare the output for the study
study.prepareOutput();

// Initialize the result writer
prepareWriter(study, pDurationCollector);

// Some checks may have failed, but we need a writer to copy the logs
// to the output directory
// So we wait until we have initialized the writer to rethrow
if (loadingException)
{
std::rethrow_exception(loadingException);
}

Antares::Solver::initializeSignalHandlers(resultWriter);

// Save about-the-study files (comments, notes, etc.)
Expand Down Expand Up @@ -410,7 +425,7 @@ void Application::readDataForTheStudy(Data::StudyLoadOptions& options)
// Apply transformations needed by the solver only (and not the interface for example)
study.performTransformationsBeforeLaunchingSimulation();

//alloc global vectors
// alloc global vectors
SIM_AllocationTableaux(study);

// Random-numbers generators
Expand Down Expand Up @@ -456,8 +471,9 @@ Application::~Application()
{
logs.info() << LOG_UI_SOLVER_DONE;

// Copy the log file
if (!pStudy->parameters.noOutput) {
// Copy the log file if a result writer is available
if (!pStudy->parameters.noOutput && resultWriter)
{
pStudy->importLogsToOutputFolder(*resultWriter);
}

Expand All @@ -469,4 +485,3 @@ Application::~Application()
}
}
} // namespace Antares::Solver

0 comments on commit 12c3abb

Please sign in to comment.