ENH: report dictionary defaults with Executable prefix

- provides better context when default values are accessed from
  a dictionary than reporting a source file location.
This commit is contained in:
Mark Olesen 2021-11-17 16:04:46 +01:00
parent bb771a3caf
commit 3d889b6dbf
3 changed files with 51 additions and 11 deletions

View File

@ -33,6 +33,7 @@ License
#include "dictionaryEntry.H"
#include "regExp.H"
#include "OSHA1stream.H"
#include "OSstream.H"
#include "argList.H"
#include "registerSwitch.H"
@ -43,6 +44,8 @@ namespace Foam
defineTypeNameAndDebug(dictionary, 0);
}
Foam::refPtr<Foam::OSstream> Foam::dictionary::reportingOutput(nullptr);
const Foam::dictionary Foam::dictionary::null;
int Foam::dictionary::writeOptionalEntries
@ -59,6 +62,14 @@ registerInfoSwitch
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::dictionary::executableName()
{
return argList::envExecutable();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dictionary::dictionary()

View File

@ -97,6 +97,7 @@ SeeAlso
#include "HashTable.H"
#include "wordList.H"
#include "className.H"
#include "refPtr.H"
// Some common data types
#include "label.H"
@ -110,6 +111,7 @@ namespace Foam
// Forward Declarations
class dictionary;
class OSstream;
class SHA1Digest;
Istream& operator>>(Istream& is, dictionary& dict);
@ -360,7 +362,11 @@ private:
//- Emit IOError about bad input for the entry
void raiseBadInput(const ITstream& is, const word& keyword) const;
//- Report (stderr) that the keyword default value was used.
//- The currently known executable name,
//- obtained from argList envExecutable
static word executableName();
//- Report (usually stderr) that the keyword default value was used,
//- or FatalIOError when writeOptionalEntries greater than 1
template<class T>
void reportDefault
@ -386,6 +392,9 @@ public:
//- An empty dictionary, which is also the parent for all dictionaries
static const dictionary null;
//- Output location when reporting default values
static refPtr<OSstream> reportingOutput;
// Static Member Functions

View File

@ -41,23 +41,41 @@ void Foam::dictionary::reportDefault
{
if (writeOptionalEntries > 1)
{
FatalIOErrorInFunction(*this)
FatalIOError(dictionary::executableName(), *this)
<< "No optional entry: " << keyword
<< " Default: " << deflt << nl
<< exit(FatalIOError);
}
InfoErr
<< "Dictionary: " << this->relativeName().c_str()
<< " Entry: " << keyword;
OSstream& os = InfoErr.stream(reportingOutput.get());
// Tag with "-- " prefix to make the message stand out
os << "-- Executable: "
<< dictionary::executableName()
<< " Dictionary: ";
// Double-quote dictionary and entry for more reliably parsing,
// especially if the keyword contains regular expressions.
if (this->isNullDict())
{
// Output as "", but could have "(null)" etc
os << token::DQUOTE << token::DQUOTE;
}
else
{
os.writeQuoted(this->relativeName(), true);
}
os << " Entry: ";
os.writeQuoted(keyword, true);
os << " Default: " << deflt;
if (added)
{
InfoErr
<< " Added";
os << " Added: true";
}
InfoErr
<< " Default: " << deflt << nl;
os << nl;
}
@ -195,14 +213,15 @@ T Foam::dictionary::getCheckOrDefault
enum keyType::option matchOpt
) const
{
#ifdef FULLDEBUG
if (!pred(deflt))
{
// Could be as FULLDEBUG instead?
FatalIOErrorInFunction(*this)
<< "Entry '" << keyword << "' with invalid default in dictionary "
<< name()
<< exit(FatalIOError);
}
#endif
const const_searcher finder(csearch(keyword, matchOpt));
@ -240,14 +259,15 @@ T Foam::dictionary::getCheckOrAdd
enum keyType::option matchOpt
)
{
#ifdef FULLDEBUG
if (!pred(deflt))
{
// Could be as FULLDEBUG instead?
FatalIOErrorInFunction(*this)
<< "Entry '" << keyword << "' with invalid default in dictionary "
<< name()
<< exit(FatalIOError);
}
#endif
const const_searcher finder(csearch(keyword, matchOpt));