ENH: add error::master() static for low-level messages

- a Pstream::master with a Pstream::parRun guard in case Pstream has
  not yet been initialised, as will be the case for low-level messages
  during startup.

- propagate relativeName handling into IOstreams
This commit is contained in:
Mark Olesen
2021-11-04 11:39:39 +01:00
parent 0bd113f537
commit 794e23e083
29 changed files with 212 additions and 171 deletions

View File

@ -84,7 +84,7 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is)
{
FatalIOErrorInFunction(is)
<< " stream not open for reading essential object from file "
<< is.name()
<< is.relativeName()
<< exit(FatalIOError);
}
@ -92,7 +92,7 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is)
{
SeriousIOErrorInFunction(is)
<< " stream not open for reading from file "
<< is.name() << endl;
<< is.relativeName() << endl;
}
return false;
@ -135,8 +135,8 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is)
FatalIOErrorInFunction(is)
<< " stream failure while reading header"
<< " on line " << is.lineNumber()
<< " of file " << is.name()
<< " for essential object" << name()
<< " of file " << is.relativeName()
<< " for essential object:" << name()
<< exit(FatalIOError);
}
@ -145,7 +145,7 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is)
InfoInFunction
<< "Stream failure while reading header"
<< " on line " << is.lineNumber()
<< " of file " << is.name() << endl;
<< " of file " << is.relativeName() << endl;
}
objState_ = BAD;

View File

@ -259,8 +259,8 @@ Foam::decomposedBlockData::readBlock
if (!headerIO.readHeader(*realIsPtr))
{
FatalIOErrorInFunction(*realIsPtr)
<< "Problem while reading header for object "
<< is.name() << nl
<< "Problem while reading object header "
<< is.relativeName() << nl
<< exit(FatalIOError);
}
}
@ -273,8 +273,8 @@ Foam::decomposedBlockData::readBlock
if (!headerIO.readHeader(headerStream))
{
FatalIOErrorInFunction(headerStream)
<< "Problem while reading header for object "
<< is.name() << nl
<< "Problem while reading object header "
<< is.relativeName() << nl
<< exit(FatalIOError);
}
streamOptData = static_cast<IOstreamOption>(headerStream);
@ -447,8 +447,8 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
if (!headerIO.readHeader(*realIsPtr))
{
FatalIOErrorInFunction(*realIsPtr)
<< "Problem while reading header for object "
<< is.name() << nl
<< "Problem while reading object header "
<< is.relativeName() << nl
<< exit(FatalIOError);
}
}

View File

@ -28,6 +28,7 @@ License
#include "IOstream.H"
#include "error.H"
#include "argList.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -48,6 +49,12 @@ Foam::fileName& Foam::IOstream::name()
}
Foam::fileName Foam::IOstream::relativeName() const
{
return argList::envRelativePath(this->name());
}
bool Foam::IOstream::check(const char* operation) const
{
return fatalCheck(operation);
@ -61,7 +68,8 @@ bool Foam::IOstream::fatalCheck(const char* operation) const
if (!ok)
{
FatalIOErrorInFunction(*this)
<< "error in IOstream " << name() << " for operation " << operation
<< "error in IOstream " << relativeName()
<< " for operation " << operation
<< exit(FatalIOError);
}

View File

@ -201,6 +201,10 @@ public:
//- Return stream name for modification
virtual fileName& name();
//- Return the name of the stream relative to the current case.
// Uses argList::envRelativePath()
fileName relativeName() const;
// Check

View File

@ -262,7 +262,7 @@ void Foam::dictionary::checkITstream
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
relativeName(), // ioFileName == dictionary name
is.lineNumber() // ioStartLineNumber
);
@ -284,7 +284,8 @@ void Foam::dictionary::checkITstream
<< remaining << " excess tokens in stream" << nl << nl;
std::cerr
<< "file: " << this->name()
// ioFileName == dictionary name
<< "file: " << relativeName()
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
@ -301,7 +302,7 @@ void Foam::dictionary::checkITstream
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
relativeName(), // ioFileName == dictionary name
is.lineNumber() // ioStartLineNumber
)
<< "Entry '" << keyword
@ -317,7 +318,8 @@ void Foam::dictionary::checkITstream
<< "' had no tokens in stream" << nl << nl;
std::cerr
<< "file: " << this->name()
// ioFileName == dictionary name
<< "file: " << relativeName()
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
@ -340,7 +342,7 @@ void Foam::dictionary::raiseBadInput
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
relativeName(), // ioFileName == dictionary name
is.lineNumber(), // ioStartLineNumber
-1 // ioEndLineNumber
)
@ -401,7 +403,7 @@ const Foam::entry& Foam::dictionary::lookupEntry
{
FatalIOErrorInFunction(*this)
<< "Entry '" << keyword << "' not found in dictionary "
<< name() << nl
<< relativeName() << nl
<< exit(FatalIOError);
}
@ -525,7 +527,7 @@ const Foam::dictionary& Foam::dictionary::subDict
{
FatalIOErrorInFunction(*this)
<< "Entry '" << keyword << "' not found in dictionary "
<< name() << nl
<< relativeName() << nl
<< exit(FatalIOError);
}
@ -545,7 +547,7 @@ Foam::dictionary& Foam::dictionary::subDict
{
FatalIOErrorInFunction(*this)
<< "Entry '" << keyword << "' not found in dictionary "
<< name() << nl
<< relativeName() << nl
<< exit(FatalIOError);
}
@ -574,7 +576,7 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd
FatalIOErrorInFunction(*this)
<< "Entry '" << keyword
<< "' is not a sub-dictionary in dictionary "
<< name() << nl
<< relativeName() << nl
<< exit(FatalIOError);
}
@ -585,7 +587,7 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd
FatalIOErrorInFunction(*this)
<< "Failed to insert sub-dictionary '" << keyword
<< "' in dictionary "
<< name() << nl
<< relativeName() << nl
<< exit(FatalIOError);
}
@ -613,7 +615,7 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict
FatalIOErrorInFunction(*this)
<< "Entry '" << keyword
<< "' is not a sub-dictionary in dictionary "
<< name() << nl
<< relativeName() << nl
<< exit(FatalIOError);
}
@ -622,7 +624,7 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict
IOWarningInFunction(*this)
<< "Entry '" << keyword
<< "' found but not a sub-dictionary in dictionary "
<< name() << endl;
<< relativeName() << endl;
}
// The move constructor properly qualifies the dictionary name
@ -649,7 +651,7 @@ const Foam::dictionary& Foam::dictionary::optionalSubDict
IOWarningInFunction(*this)
<< "Entry '" << keyword
<< "' found but not a sub-dictionary in dictionary "
<< name() << endl;
<< relativeName() << endl;
}
return *this;
@ -737,7 +739,7 @@ Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
IOWarningInFunction(*this)
<< "Problem replacing entry "<< entryPtr->keyword()
<< " in dictionary " << name() << endl;
<< " in dictionary " << relativeName() << endl;
parent_type::remove(entryPtr);
@ -765,7 +767,8 @@ Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
IOWarningInFunction(*this)
<< "Attempt to add entry " << entryPtr->keyword()
<< " which already exists in dictionary " << name() << endl;
<< " which already exists in dictionary "
<< relativeName() << endl;
delete entryPtr;
return nullptr;
@ -871,7 +874,7 @@ bool Foam::dictionary::merge(const dictionary& dict)
{
FatalIOErrorInFunction(*this)
<< "Attempted merge to self, for dictionary "
<< name() << nl
<< relativeName() << nl
<< abort(FatalIOError);
}
@ -960,7 +963,7 @@ void Foam::dictionary::operator+=(const dictionary& rhs)
{
FatalIOErrorInFunction(*this)
<< "Attempted addition to self, for dictionary "
<< name() << nl
<< relativeName() << nl
<< abort(FatalIOError);
}
@ -977,7 +980,7 @@ void Foam::dictionary::operator|=(const dictionary& rhs)
{
FatalIOErrorInFunction(*this)
<< "Attempted |= merging to self, for dictionary "
<< name() << nl
<< relativeName() << nl
<< abort(FatalIOError);
}
@ -997,7 +1000,7 @@ void Foam::dictionary::operator<<=(const dictionary& rhs)
{
FatalIOErrorInFunction(*this)
<< "Attempted addition to self, for dictionary "
<< name() << nl
<< relativeName() << nl
<< abort(FatalIOError);
}

View File

@ -50,21 +50,14 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat
if (finder.good())
{
// Want single warning (on master), but guard with parRun to avoid
// Pstream::master() when Pstream has not yet been initialized
if
(
(Pstream::parRun() ? Pstream::master() : true)
&& error::warnAboutAge(alt.second)
)
if (error::warnAboutAge(alt.second) && error::master())
{
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Found [v" << alt.second << "] '"
<< alt.first << "' entry instead of '"
<< keyword.c_str() << "' in dictionary \""
<< name().c_str() << "\" "
<< nl
<< relativeName() << '"' << nl
<< std::endl;
error::warnAboutAge("keyword", alt.second);
@ -113,7 +106,7 @@ const Foam::entry& Foam::dictionary::lookupEntryCompat
{
FatalIOErrorInFunction(*this)
<< "Entry '" << keyword << "' not found in dictionary "
<< name()
<< relativeName()
<< exit(FatalIOError);
}

View File

@ -125,6 +125,12 @@ public:
return dictionary::name();
}
//- Return scoped dictionary name relative to the current case
virtual fileName relativeName() const
{
return dictionary::relativeName();
}
//- Return line number of first token in dictionary
virtual label startLineNumber() const;
@ -132,7 +138,7 @@ public:
virtual label endLineNumber() const;
//- This entry is not a primitive,
// calling this function generates a FatalError
//- calling this function generates a FatalError
virtual ITstream& stream() const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -44,6 +44,20 @@ Foam::entry::inputMode Foam::entry::globalInputMode = inputMode::MERGE;
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::entry::reportReadWarning
(
const IOstream& is,
const std::string& msg
)
{
std::cerr
<< "--> FOAM Warning :\n"
<< " Reading \"" << is.relativeName()
<< "\" at line " << is.lineNumber() << '\n'
<< " " << msg << std::endl;
}
void Foam::entry::resetInputMode()
{
globalInputMode = inputMode::MERGE;
@ -85,7 +99,7 @@ void Foam::entry::raiseBadInput(const ITstream& is) const
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
this->relativeName(), // ioFileName
is.lineNumber() // ioStartLineNumber
)
<< "Entry '" << keyword << "' with invalid input" << nl << nl
@ -110,7 +124,7 @@ void Foam::entry::checkITstream(const ITstream& is) const
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
this->relativeName(), // ioFileName
is.lineNumber() // ioStartLineNumber
);
@ -132,7 +146,7 @@ void Foam::entry::checkITstream(const ITstream& is) const
<< remaining << " excess tokens in stream" << nl << nl;
std::cerr
<< "file: " << this->name()
<< "file: " << this->relativeName()
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;
@ -149,7 +163,7 @@ void Foam::entry::checkITstream(const ITstream& is) const
"", // functionName
"", // sourceFileName
0, // sourceFileLineNumber
this->name(), // ioFileName
this->relativeName(), // ioFileName
is.lineNumber() // ioStartLineNumber
)
<< "Entry '" << keyword
@ -165,7 +179,7 @@ void Foam::entry::checkITstream(const ITstream& is) const
<< "' had no tokens in stream" << nl << nl;
std::cerr
<< "file: " << this->name()
<< "file: " << this->relativeName()
<< " at line " << is.lineNumber() << '.' << nl
<< std::endl;

View File

@ -87,7 +87,7 @@ public:
private:
// Private data
// Private Data
//- Keyword of entry
keyType keyword_;
@ -114,6 +114,14 @@ private:
void raiseBadInput(const ITstream& is) const;
protected:
// Protected Member Functions
//- Report a read warning (on std::cerr)
static void reportReadWarning(const IOstream&, const std::string&);
public:
//- Enable or disable use of function entries and variable expansions.
@ -202,6 +210,9 @@ public:
//- Return the entry name for modification
virtual fileName& name() = 0;
//- Return the entry name relative to the current case
virtual fileName relativeName() const = 0;
//- Return line number of first token in dictionary
virtual label startLineNumber() const = 0;

View File

@ -92,10 +92,11 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
<< "--> FOAM Warning :" << nl
<< " From function " << FUNCTION_NAME << nl
<< " in file " << __FILE__ << " at line " << __LINE__ << nl
<< " Reading " << is.name() << nl
<< " Reading " << is.relativeName() << nl
<< " found " << keyToken << nl
<< " expected either " << token::END_BLOCK << " or EOF"
<< std::endl;
return false;
}

View File

@ -68,8 +68,9 @@ Foam::string Foam::functionEntries::calcEntry::evaluate
)
{
DetailInfo
<< "Using #calc at line " << is.lineNumber()
<< " in file " << parentDict.name() << endl;
<< "Using #calc - line "
<< is.lineNumber() << " in file "
<< parentDict.relativeName() << nl;
dynamicCode::checkSecurity
(

View File

@ -356,7 +356,7 @@ Foam::string Foam::functionEntries::codeStream::evaluate
{
DetailInfo
<< "Using #codeStream at line " << is.lineNumber()
<< " in file " << parentDict.name() << endl;
<< " in file " << parentDict.relativeName() << endl;
dynamicCode::checkSecurity
(

View File

@ -58,25 +58,6 @@ namespace functionEntries
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace
{
// This is akin to a SafeIOWarning, which does not yet exist
inline void safeIOWarning
(
const Foam::IOstream& is,
const std::string& msg
)
{
std::cerr
<< "--> FOAM Warning :\n"
<< " Reading \"" << is.name() << "\" at line "
<< is.lineNumber() << '\n'
<< " " << msg << std::endl;
}
} // End anonymous namespace
namespace Foam
{
@ -158,8 +139,6 @@ static bool slurpUntilBalancedBrace(ISstream& is, std::string& str)
str.append(buf, nChar); // Finalize pending content
safeIOWarning(is, "Premature end while reading expression - missing '}'?");
is.fatalCheck(FUNCTION_NAME);
return false;
}
@ -252,7 +231,8 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
{
InfoErr
<< "Empty #eval - line "
<< is.lineNumber() << " in file " << parentDict.name() << nl;
<< is.lineNumber() << " in file "
<< parentDict.relativeName() << nl;
return tokenList();
}
@ -268,7 +248,8 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
{
InfoErr
<< "Failed #eval - line "
<< is.lineNumber() << " in file " << parentDict.name() << nl;
<< is.lineNumber() << " in file "
<< parentDict.relativeName() << nl;
return tokenList();
}
@ -296,7 +277,8 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
#ifdef FULLDEBUG
DetailInfo
<< "Using #eval - line "
<< is.lineNumber() << " in file " << parentDict.name() << nl;
<< is.lineNumber() << " in file "
<< parentDict.relativeName() << nl;
#endif
token tok(is);
@ -321,7 +303,14 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
else if (tok.isPunctuation(token::BEGIN_BLOCK))
{
// - #eval { expr }
slurpUntilBalancedBrace(dynamic_cast<ISstream&>(is), str);
if (!slurpUntilBalancedBrace(dynamic_cast<ISstream&>(is), str))
{
reportReadWarning
(
is,
"Premature end while reading expression - missing '}'?"
);
}
}
else
{

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -71,7 +72,7 @@ Foam::functionEntry::functionEntry
:
primitiveEntry
(
word(key+dict.name()+Foam::name(is.lineNumber())),
word(key + dict.name() + Foam::name(is.lineNumber())),
readLine(key, is)
)
{}
@ -106,9 +107,9 @@ bool Foam::functionEntry::execute
{
FatalErrorInFunction
<< "Unknown functionEntry '" << functionName
<< "' in " << is.name() << " near line " << is.lineNumber()
<< nl << nl
<< "Valid functionEntries :" << endl
<< "' in " << is.relativeName()
<< " near line " << is.lineNumber() << nl << nl
<< "Valid functionEntries :" << nl
<< executedictionaryIstreamMemberFunctionTablePtr_->sortedToc()
<< exit(FatalError);
}
@ -148,9 +149,9 @@ bool Foam::functionEntry::execute
{
FatalErrorInFunction
<< "Unknown functionEntry '" << functionName
<< "' in " << is.name() << " near line " << is.lineNumber()
<< nl << nl
<< "Valid functionEntries :" << endl
<< "' in " << is.relativeName()
<< " near line " << is.lineNumber() << nl << nl
<< "Valid functionEntries :" << nl
<< executeprimitiveEntryIstreamMemberFunctionTablePtr_->sortedToc()
<< exit(FatalError);
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -48,15 +49,15 @@ SourceFiles
#ifndef functionEntry_H
#define functionEntry_H
#include "word.H"
#include "memberFunctionSelectionTables.H"
#include "primitiveEntry.H"
#include "memberFunctionSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class dictionary;
/*---------------------------------------------------------------------------*\
@ -67,17 +68,10 @@ class functionEntry
:
public primitiveEntry
{
// Private Member Functions
//- No copy construct
functionEntry(const functionEntry&) = delete;
//- No copy assignment
void operator=(const functionEntry&) = delete;
protected:
// Protected Member Functions
//- Read line and return as a string token
static token readLine(const word& key, Istream& is);
@ -86,6 +80,12 @@ protected:
template<class StringType>
static List<StringType> readStringList(Istream& is);
//- No copy construct
functionEntry(const functionEntry&) = delete;
//- No copy assignment
void operator=(const functionEntry&) = delete;
public:
// Constructors

View File

@ -391,8 +391,8 @@ bool Foam::functionEntries::ifeqEntry::execute
if (ifEntry::isTrue(e.stream()))
{
// Info<< "Using #elif " << doIf << " at line " << lineNo
// << " in file " << is.name() << endl;
// Info<< "Using #elif " << doIf << " - line " << lineNo
// << " in file " << is.relativeName() << endl;
break;
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -170,7 +170,7 @@ bool Foam::functionEntries::includeEntry::execute
FatalIOErrorInFunction(is)
<< "Cannot open include file "
<< (ifs.name().size() ? ifs.name() : rawName)
<< " while reading dictionary " << parentDict.name()
<< " while reading dictionary " << parentDict.relativeName()
<< exit(FatalIOError);
return false;
@ -222,7 +222,7 @@ bool Foam::functionEntries::includeEntry::execute
FatalIOErrorInFunction(is)
<< "Cannot open include file "
<< (ifs.name().size() ? ifs.name() : rawName)
<< " while reading dictionary " << parentDict.name()
<< " while reading dictionary " << parentDict.relativeName()
<< exit(FatalIOError);
return false;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2017 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -138,7 +138,7 @@ bool Foam::functionEntries::includeEtcEntry::execute
FatalIOErrorInFunction(is)
<< "Cannot open etc file "
<< (ifs.name().size() ? ifs.name() : rawName)
<< " while reading dictionary " << parentDict.name()
<< " while reading dictionary " << parentDict.relativeName()
<< exit(FatalIOError);
return false;
@ -178,7 +178,7 @@ bool Foam::functionEntries::includeEtcEntry::execute
FatalIOErrorInFunction(is)
<< "Cannot open etc file "
<< (ifs.name().size() ? ifs.name() : rawName)
<< " while reading dictionary " << parentDict.name()
<< " while reading dictionary " << parentDict.relativeName()
<< exit(FatalIOError);
return false;

View File

@ -155,6 +155,12 @@ public:
return ITstream::name();
}
//- Return token stream name relative to the current case
virtual fileName relativeName() const
{
return ITstream::relativeName();
}
//- Return line number of first token in dictionary
virtual label startLineNumber() const;

View File

@ -30,27 +30,6 @@ License
#include "functionEntry.H"
#include "evalEntry.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace
{
// This is akin to a SafeIOWarning, which does not yet exist
inline void safeIOWarning
(
const Foam::IOstream& is,
const std::string& msg
)
{
std::cerr
<< "--> FOAM Warning :\n"
<< " Reading \"" << is.name() << "\" at line "
<< is.lineNumber() << '\n'
<< " " << msg << std::endl;
}
} // End anonymous namespace
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::primitiveEntry::acceptToken
@ -182,7 +161,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
--depth;
if (depth < 0)
{
safeIOWarning
reportReadWarning
(
is,
"Too many closing ')' ... was a ';' forgotten?"
@ -191,7 +170,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
else if (depth < 61 && ((balanced >> depth) & 1u))
{
// Bit was set, but expected it to be unset.
safeIOWarning(is, "Imbalanced '{' with ')'");
reportReadWarning(is, "Imbalanced '{' with ')'");
}
}
break;
@ -201,7 +180,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
--depth;
if (depth < 0)
{
safeIOWarning
reportReadWarning
(
is,
"Too many closing '}' ... was a ';' forgotten?"
@ -210,7 +189,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
else if (depth < 61 && !((balanced >> depth) & 1u))
{
// Bit was unset, but expected it to be set.
safeIOWarning(is, "Imbalanced '(' with '}'");
reportReadWarning(is, "Imbalanced '(' with '}'");
}
}
break;
@ -230,7 +209,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
if (depth)
{
safeIOWarning(is, "Imbalanced brackets");
reportReadWarning(is, "Imbalanced brackets");
}
is.fatalCheck(FUNCTION_NAME);

View File

@ -27,7 +27,6 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "argList.H"
#include "StringStream.H"
#include "fileName.H"
#include "dictionary.H"
@ -100,7 +99,7 @@ Foam::OSstream& Foam::IOerror::operator()
functionName,
sourceFileName,
sourceFileLineNumber,
argList::envRelativePath(ioStream.name()),
ioStream.relativeName(),
ioStream.lineNumber(),
-1 // No known endLineNumber
);
@ -137,8 +136,8 @@ Foam::OSstream& Foam::IOerror::operator()
(
where.c_str(),
"", // No source file
1, // Non-zero to ensure that 'where' is reported
argList::envRelativePath(ioStream.name()),
-1, // Non-zero to ensure 'where' is reported
ioStream.relativeName(),
ioStream.lineNumber(),
-1 // No known endLineNumber
);
@ -155,7 +154,7 @@ Foam::OSstream& Foam::IOerror::operator()
(
where.c_str(),
"", // No source file
1, // Non-zero to ensure that 'where' is reported
-1, // Non-zero to ensure 'where' is reported
dict.relativeName(),
dict.startLineNumber(),
dict.endLineNumber()
@ -188,7 +187,7 @@ void Foam::IOerror::SafeFatalIOError
<< nl
<< "--> FOAM FATAL IO ERROR:" << nl
<< msg << nl
<< "file: " << ioStream.name()
<< "file: " << ioStream.relativeName()
<< " at line " << ioStream.lineNumber() << '.' << nl << nl
<< " From " << functionName << nl
<< " in file " << sourceFileName
@ -253,7 +252,7 @@ void Foam::IOerror::abort()
}
void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
void Foam::IOerror::write(Ostream& os, const bool withTitle) const
{
if (os.bad())
{
@ -261,7 +260,7 @@ void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
}
os << nl;
if (includeTitle && !title().empty())
if (withTitle && !title().empty())
{
os << title().c_str()
<< "(openfoam-" << foamVersion::api;

View File

@ -38,6 +38,20 @@ License
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
bool Foam::error::master(const label communicator)
{
// Trap negative value for comm as 'default'. This avoids direct use
// of Pstream::worldComm which may not have been initialised
return
(
UPstream::parRun()
? (communicator < 0 ? UPstream::master() : UPstream::master(communicator))
: true
);
}
bool Foam::error::warnAboutAge(const int version) noexcept
{
// No warning for 0 (unversioned) or -ve values (silent versioning)
@ -245,20 +259,20 @@ void Foam::error::simpleExit(const int errNo, const bool isAbort)
error::printStack(Perr);
std::abort();
}
else if (Pstream::parRun())
else if (UPstream::parRun())
{
if (isAbort)
{
Perr<< nl << *this << nl
<< "\nFOAM parallel run aborting\n" << endl;
error::printStack(Perr);
Pstream::abort();
UPstream::abort();
}
else
{
Perr<< nl << *this << nl
<< "\nFOAM parallel run exiting\n" << endl;
Pstream::exit(errNo);
UPstream::exit(errNo);
}
}
else
@ -326,7 +340,7 @@ void Foam::error::abort()
}
void Foam::error::write(Ostream& os, const bool includeTitle) const
void Foam::error::write(Ostream& os, const bool withTitle) const
{
if (os.bad())
{
@ -334,7 +348,7 @@ void Foam::error::write(Ostream& os, const bool includeTitle) const
}
os << nl;
if (includeTitle && !title().empty())
if (withTitle && !title().empty())
{
os << title().c_str()
<< "(openfoam-" << foamVersion::api;

View File

@ -119,6 +119,13 @@ public:
// Static Functions
//- Like Pstream::master but with a Pstream::parRun guard in case
//- Pstream has not yet been initialised.
//
// \param communicator is the numbered MPI communicator.
// By default it uses UPstream::worldComm
static bool master(const label communicator = -1);
//- Test if an age warning should be emitted.
// \param version is the old version (YYMM) for determining the
// age in months compared to the current OpenFOAM version
@ -244,7 +251,7 @@ public:
void abort();
//- Print error message
virtual void write(Ostream& os, const bool includeTitle = true) const;
virtual void write(Ostream& os, const bool withTitle = true) const;
// Housekeeping
@ -405,7 +412,7 @@ public:
void abort();
//- Print error message
virtual void write(Ostream& os, const bool includeTitle = true) const;
virtual void write(Ostream& os, const bool withTitle = true) const;
};

View File

@ -80,10 +80,10 @@ Foam::OSstream& Foam::messageStream::stream(OSstream* alternative)
|| severity_ == INFO_STDERR
|| severity_ == WARNING
)
|| !Pstream::parRun()
|| !UPstream::parRun()
);
if (serialOnly && (Pstream::parRun() && !Pstream::master()))
if (serialOnly && (UPstream::parRun() && !UPstream::master()))
{
return Snull; // Non-serial, non-master: exit early
}

View File

@ -571,6 +571,7 @@ Foam::word Foam::argList::optionCompat(const word& optName)
{
const auto& alt = fnd.val();
// No error::master() guard - only called on master anyhow
if (error::warnAboutAge(alt.second))
{
std::cerr
@ -609,6 +610,7 @@ int Foam::argList::optionIgnore(const word& optName)
// '-option ARG' or '-option'
const int nskip = (alt.first ? 2 : 1);
// No error::master() guard - only called on master anyhow
if (error::warnAboutAge(alt.second))
{
std::cerr

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -161,9 +161,7 @@ static void expandLeadingTilde(std::string& s)
// Compat Warning
const int version(1806);
// Single warning (on master) with guard to avoid Pstream::master()
// when Pstream has not yet been initialized
if (UPstream::parRun() ? UPstream::master() : true)
if (error::master())
{
std::cerr
<< nl

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -56,19 +56,21 @@ const Foam::dictionary* Foam::coordinateSystem::subDictCompat
const word csName(finder.ref().stream());
// Deprecated, unsupported syntax
if (error::master())
{
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Ignoring 'coordinateSystem' as a keyword."
" Perhaps you meant this instead?" << nl
<< '{' << nl
<< " type " << coordSystem::indirect::typeName_()
<< ';' << nl
<< " name " << csName << ';' << nl
<< '}' << nl
<< std::endl;
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Ignoring 'coordinateSystem' as a keyword."
" Perhaps you meant this instead?" << nl
<< '{' << nl
<< " type " << coordSystem::indirect::typeName_()
<< ';' << nl
<< " name " << csName << ';' << nl
<< '}' << nl
<< std::endl;
error::warnAboutAge("syntax change", 1806);
error::warnAboutAge("syntax change", 1806);
}
}
}

View File

@ -60,12 +60,15 @@ void Foam::coordinateSystems::readFromStream(const bool valid)
else if (headerClassName() == headerTypeCompat)
{
// Older (1806 and earlier) header name
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Found header class name '" << headerTypeCompat
<< "' instead of '" << typeName << "'" << nl;
if (error::master())
{
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Found header class name '" << headerTypeCompat
<< "' instead of '" << typeName << "'" << nl;
error::warnAboutAge("header class", 1806);
error::warnAboutAge("header class", 1806);
}
this->readIstream(is, coordinateSystem::iNew());
close();

View File

@ -55,12 +55,12 @@ namespace Foam
static inline void warnCompatDegrees(const Foam::dictionary& dict)
{
if (Pstream::parRun() ? Pstream::master() : true)
if (error::master())
{
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Found [v1806] 'degrees' keyword in dictionary \""
<< dict.name().c_str() << "\" Ignored, now radians only." << nl
<< dict.relativeName() << "\" Ignored, now radians only." << nl
<< std::endl;
}
}