Skip to content

Handle potential exceptions from preCICE calls #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

MakisH
Copy link
Member

@MakisH MakisH commented Apr 8, 2025

Closes #362.

Every exception is just handled by throwing an error message, but this still leads to nicer output than the complete call stack. For example, simply:

---[precice] ERROR:  Sending data to another participant (using sockets) failed with a system error: write: Broken pipe. This often means that the other participant exited with an error (look there).

compared to previous state:

---[precice] ERROR:  Receiving data from another participant (using sockets) failed with a system error: read: End of file. This often means that the other participant exited with an error (look there).
terminate called after throwing an instance of 'precice::Error'
  what():  Receiving data from another participant (using sockets) failed with a system error: read: End of file. This often means that the other participant exited with an error (look there).
[tickly:49174] *** Process received signal ***
[tickly:49174] Signal: Aborted (6)
[tickly:49174] Signal code:  (-6)
[tickly:49174] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x71f76fc42520]
[tickly:49174] [ 1] /lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x71f76fc969fc]
[tickly:49174] [ 2] /lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x71f76fc42476]
[tickly:49174] [ 3] /lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x71f76fc287f3]
[tickly:49174] [ 4] /lib/x86_64-linux-gnu/libstdc++.so.6(+0xa2b9e)[0x71f7700a2b9e]
[tickly:49174] [ 5] /lib/x86_64-linux-gnu/libstdc++.so.6(+0xae20c)[0x71f7700ae20c]
[tickly:49174] [ 6] /lib/x86_64-linux-gnu/libstdc++.so.6(+0xae277)[0x71f7700ae277]
[tickly:49174] [ 7] /lib/x86_64-linux-gnu/libstdc++.so.6(+0xae4d8)[0x71f7700ae4d8]
[tickly:49174] [ 8] /home/gc/repos/precice/precice/build/libprecice.so.3(+0x953ba)[0x71f76bc953ba]
[tickly:49174] [ 9] /home/gc/repos/precice/precice/build/libprecice.so.3(+0x7bf3e0)[0x71f76c3bf3e0]
[tickly:49174] [10] /home/gc/repos/precice/precice/build/libprecice.so.3(+0x53d408)[0x71f76c13d408]
[tickly:49174] [11] /home/gc/repos/precice/precice/build/libprecice.so.3(+0x5ac081)[0x71f76c1ac081]
[tickly:49174] [12] /home/gc/repos/precice/precice/build/libprecice.so.3(+0x5bbd0b)[0x71f76c1bbd0b]
[tickly:49174] [13] /home/gc/repos/precice/precice/build/libprecice.so.3(+0x5a5390)[0x71f76c1a5390]
[tickly:49174] [14] /home/gc/repos/precice/precice/build/libprecice.so.3(+0x697b0f)[0x71f76c297b0f]
[tickly:49174] [15] /home/gc/repos/precice/precice/build/libprecice.so.3(+0x67c9e9)[0x71f76c27c9e9]
[tickly:49174] [16] /home/gc/repos/precice/precice/build/libprecice.so.3(_ZN7precice11Participant7advanceEd+0x35)[0x71f76c265a2b]
[tickly:49174] [17] /home/gc/OpenFOAM/gc-v2412/platforms/linux64GccDPInt32Opt/lib/libpreciceAdapterFunctionObject.so(_ZN14preciceAdapter7Adapter7executeEv+0xa1)[0x71f76cd8e001]
[tickly:49174] [18] /home/gc/OpenFOAM/gc-v2412/platforms/linux64GccDPInt32Opt/lib/libpreciceAdapterFunctionObject.so(_ZN4Foam15functionObjects28preciceAdapterFunctionObject7executeEv+0x11)[0x71f76cdb5d61]
[tickly:49174] [19] /usr/lib/openfoam/openfoam2412/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZN4Foam18functionObjectList7executeEb+0x100)[0x71f77081e0f0]
[tickly:49174] [20] /usr/lib/openfoam/openfoam2412/platforms/linux64GccDPInt32Opt/lib/libOpenFOAM.so(_ZNK4Foam4Time3runEv+0x1f1)[0x71f770833df1]
[tickly:49174] [21] pimpleFoam(+0x19d56)[0x5b694cf4ad56]
[tickly:49174] [22] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x71f76fc29d90]
[tickly:49174] [23] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x71f76fc29e40]
[tickly:49174] [24] pimpleFoam(+0x21e35)[0x5b694cf52e35]
[tickly:49174] *** End of error message ***
Aborted (core dumped)

Not sure if there is any point in actually including the .what(). This should always be duplicated, right? Including it leads to this:

---[precice] ERROR:  Receiving data from another participant (using sockets) failed with a system error: read: End of file. This often means that the other participant exited with an error (look there).


--> FOAM FATAL ERROR: (openfoam-2412)
Error in the preCICE adapter: 
There was an issue while trying to advance preCICE:
Receiving data from another participant (using sockets) failed with a system error: read: End of file. This often means that the other participant exited with an error (look there).


    From void adapterInfo(std::string, std::string)
    in file Utilities.C at line 32.

FOAM exiting

Also not sure if we want to actually trigger a Foam::FatalError via our logger. It does not really add much more information, besides that the error comes from the adapter.

@fsimonis can we assume that some API methods (such as the boolean checks) never throw? Would a noexcept keyword in these API methods make sense?

TODO list:

  • I updated the documentation in docs/ -> N/A
  • I added a changelog entry in changelog-entries/ (create directory if missing)

@MakisH MakisH self-assigned this Apr 8, 2025
@MakisH MakisH marked this pull request as ready for review April 8, 2025 09:40
@MakisH MakisH requested a review from davidscn April 8, 2025 09:41
@MakisH
Copy link
Member Author

MakisH commented Apr 8, 2025

The system tests pass, the issues previously were related to the runner: https://github.com/precice/openfoam-adapter/actions/runs/14330310572/job/40172178566?pr=366

Copy link
Member

@davidscn davidscn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there is any point in actually including the .what(). This should always be duplicated, right? Including it leads to this:

Actually no, I don't think so. It should only appear if we actually print (using what) in the catch block. It could be related to how we interface with boost log, I vaguely remember some issues we had with ASTE as well.

Regarding this issue. I am not 100% convinced of all the try's which are now sprinkled across the entire code. A less scattered alternative would be to wrap highlevel functions in the Adapter class in a try-catch block.

We could still catch the precice exceptions using using catch(::precice::Error). This would not work with former preCICE versions then, but we can use our version macros to distinguish and have something like

#if PRECICE_VERSION_GTE(3,2,0)
using PreciceError = ::precice::Error
#else
using PreciceError = std::runtime_error
#endif

If the else branch becomes unnecessary at some point, we can remove it and have the clean solution.

Comment on lines +548 to +567
bool requiresInitialData = false;
try
{
precice_->requiresInitialData();
}
catch (const std::runtime_error& e)
{
std::exit(1);
}
if (requiresInitialData)
{
DEBUG(adapterInfo("Initializing preCICE data..."));
writeCouplingData();
}

DEBUG(adapterInfo("Initializing preCICE data..."));
precice_->initialize();
try
{
precice_->initialize();
}
catch (const std::runtime_error& e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a rather verbose way of handling this, also a bit hard to read. Why not simply wrapping the whole code block into a try catch?

try{
 if (precice_->requiresInitialData())
  precice_->initialize()
  } catch(...)
{}

}

}
catch (const std::runtime_error& e)
{
std::exit(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::exit(1);
std::exit(EXIT_FAILURE);

@@ -702,6 +734,20 @@ void preciceAdapter::Adapter::adjustSolverTimeStepAndReadData()
return;
}

double preciceAdapter::Adapter::getMaxTimeStepSize()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
double preciceAdapter::Adapter::getMaxTimeStepSize()
double preciceAdapter::Adapter::getMaxTimeStepSize() const

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not handling preCICE exceptions
2 participants