mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support true/false, yes/no values for FOAM_ABORT (#1896)
- consistent with FOAM_SIGFPE etc. - centralize code as error::useAbort() static function to avoid scattering the logic throughout the code. ENH: also accept "0" and "1" string values for Switch - not the normal path for Switch input (eg, from a dictionary), but consistent with bool definitions and simplifies string parsing. This means that `FOAM_SIGFPE=1 application` will now also work.
This commit is contained in:
@ -129,6 +129,10 @@ projectDir="$HOME/OpenFOAM/OpenFOAM-$WM_PROJECT_VERSION"
|
|||||||
# = true | false
|
# = true | false
|
||||||
#export FOAM_SETNAN=false
|
#export FOAM_SETNAN=false
|
||||||
|
|
||||||
|
# [FOAM_ABORT] - Treat exit() on FatalError as abort()
|
||||||
|
# = true | false
|
||||||
|
#export FOAM_ABORT=false
|
||||||
|
|
||||||
# [FOAM_CODE_TEMPLATES] - dynamicCode templates
|
# [FOAM_CODE_TEMPLATES] - dynamicCode templates
|
||||||
# - unset: uses 'foamEtcFile -list codeTemplates/dynamicCode'
|
# - unset: uses 'foamEtcFile -list codeTemplates/dynamicCode'
|
||||||
##export FOAM_CODE_TEMPLATES="$WM_PROJECT_DIR/etc/codeTemplates/dynamicCode"
|
##export FOAM_CODE_TEMPLATES="$WM_PROJECT_DIR/etc/codeTemplates/dynamicCode"
|
||||||
|
|||||||
@ -131,6 +131,10 @@ set projectDir=`lsof +p $$ |& sed -ne 's#^[^/]*##;\@/'"$projectName"'[^/]*/etc/c
|
|||||||
# = true | false
|
# = true | false
|
||||||
#setenv FOAM_SETNAN false
|
#setenv FOAM_SETNAN false
|
||||||
|
|
||||||
|
# [FOAM_ABORT] - Treat exit() on FatalError as abort()
|
||||||
|
# = true | false
|
||||||
|
#setenv FOAM_ABORT false
|
||||||
|
|
||||||
# [FOAM_CODE_TEMPLATES] - dynamicCode templates
|
# [FOAM_CODE_TEMPLATES] - dynamicCode templates
|
||||||
# - unset: uses 'foamEtcFile -list codeTemplates/dynamicCode'
|
# - unset: uses 'foamEtcFile -list codeTemplates/dynamicCode'
|
||||||
##setenv FOAM_CODE_TEMPLATES "$WM_PROJECT_DIR/etc/codeTemplates/dynamicCode"
|
##setenv FOAM_CODE_TEMPLATES "$WM_PROJECT_DIR/etc/codeTemplates/dynamicCode"
|
||||||
|
|||||||
@ -177,7 +177,7 @@ void Foam::IOerror::exitOrAbort(const int errNo, const bool isAbort)
|
|||||||
if (!throwing_ && JobInfo::constructed)
|
if (!throwing_ && JobInfo::constructed)
|
||||||
{
|
{
|
||||||
jobInfo.add("FatalIOError", operator dictionary());
|
jobInfo.add("FatalIOError", operator dictionary());
|
||||||
if (isAbort || hasEnv("FOAM_ABORT"))
|
if (isAbort || error::useAbort())
|
||||||
{
|
{
|
||||||
jobInfo.abort();
|
jobInfo.abort();
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ void Foam::IOerror::exitOrAbort(const int errNo, const bool isAbort)
|
|||||||
|
|
||||||
throw errorException;
|
throw errorException;
|
||||||
}
|
}
|
||||||
else if (hasEnv("FOAM_ABORT"))
|
else if (error::useAbort())
|
||||||
{
|
{
|
||||||
Perr<< nl << *this << nl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
||||||
|
|||||||
@ -34,6 +34,7 @@ License
|
|||||||
#include "Pstream.H"
|
#include "Pstream.H"
|
||||||
#include "foamVersion.H"
|
#include "foamVersion.H"
|
||||||
#include "OSspecific.H"
|
#include "OSspecific.H"
|
||||||
|
#include "Switch.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -70,6 +71,13 @@ void Foam::error::warnAboutAge(const char* what, const int version)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::error::useAbort()
|
||||||
|
{
|
||||||
|
// FOAM_ABORT env set and contains bool-type value
|
||||||
|
return static_cast<bool>(Switch::find(Foam::getEnv("FOAM_ABORT")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::error::error(const string& title)
|
Foam::error::error(const string& title)
|
||||||
@ -197,7 +205,7 @@ void Foam::error::exitOrAbort(const int errNo, const bool isAbort)
|
|||||||
if (!throwing_ && JobInfo::constructed)
|
if (!throwing_ && JobInfo::constructed)
|
||||||
{
|
{
|
||||||
jobInfo.add("FatalError", operator dictionary());
|
jobInfo.add("FatalError", operator dictionary());
|
||||||
if (isAbort || hasEnv("FOAM_ABORT"))
|
if (isAbort || error::useAbort())
|
||||||
{
|
{
|
||||||
jobInfo.abort();
|
jobInfo.abort();
|
||||||
}
|
}
|
||||||
@ -217,7 +225,7 @@ void Foam::error::exitOrAbort(const int errNo, const bool isAbort)
|
|||||||
|
|
||||||
throw errorException;
|
throw errorException;
|
||||||
}
|
}
|
||||||
else if (hasEnv("FOAM_ABORT"))
|
else if (error::useAbort())
|
||||||
{
|
{
|
||||||
Perr<< nl << *this << nl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
||||||
|
|||||||
@ -215,6 +215,9 @@ public:
|
|||||||
//- Helper function to print a stack
|
//- Helper function to print a stack
|
||||||
static void printStack(Ostream& os);
|
static void printStack(Ostream& os);
|
||||||
|
|
||||||
|
//- True if FOAM_ABORT is on.
|
||||||
|
static bool useAbort();
|
||||||
|
|
||||||
//- Exit : can be called for any error to exit program.
|
//- Exit : can be called for any error to exit program.
|
||||||
// Redirects to abort() when FOAM_ABORT is on.
|
// Redirects to abort() when FOAM_ABORT is on.
|
||||||
void exit(const int errNo = 1);
|
void exit(const int errNo = 1);
|
||||||
|
|||||||
@ -71,7 +71,7 @@ namespace Foam
|
|||||||
//- Mimic exit handling of the error class
|
//- Mimic exit handling of the error class
|
||||||
static void exitNow(const error& err)
|
static void exitNow(const error& err)
|
||||||
{
|
{
|
||||||
if (hasEnv("FOAM_ABORT"))
|
if (error::useAbort())
|
||||||
{
|
{
|
||||||
Perr<< nl << err << nl
|
Perr<< nl << err << nl
|
||||||
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
||||||
|
|||||||
@ -92,13 +92,13 @@ Foam::Switch::switchType Foam::Switch::parse
|
|||||||
{
|
{
|
||||||
switch (str.size())
|
switch (str.size())
|
||||||
{
|
{
|
||||||
case 1: // (f|n|t|y) - single-character forms
|
case 1: // (0|1|f|t|n|y)
|
||||||
{
|
{
|
||||||
switch (str[0])
|
switch (str[0])
|
||||||
{
|
{
|
||||||
case 'f': return switchType::FALSE;
|
case '0': case 'f': return switchType::FALSE;
|
||||||
|
case '1': case 't': return switchType::TRUE;
|
||||||
case 'n': return switchType::NO;
|
case 'n': return switchType::NO;
|
||||||
case 't': return switchType::TRUE;
|
|
||||||
case 'y': return switchType::YES;
|
case 'y': return switchType::YES;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -29,7 +29,8 @@ Class
|
|||||||
|
|
||||||
Description
|
Description
|
||||||
A simple wrapper around bool so that it can be read as a word:
|
A simple wrapper around bool so that it can be read as a word:
|
||||||
true/false, on/off, yes/no, y/n, t/f, or none.
|
true/false, on/off, yes/no, any/none.
|
||||||
|
Also accepts 0/1 as a string and shortcuts t/f, y/n.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
Switch.C
|
Switch.C
|
||||||
|
|||||||
Reference in New Issue
Block a user