Commit 3f06722a authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: suppress IOerror newlines if file name is empty

- compacter messages in some cases

STYLE: simplify output handling of line numbers
parent c9cb4ce3
......@@ -165,25 +165,24 @@ Foam::ITstream::ITstream
void Foam::ITstream::print(Ostream& os) const
{
os << "ITstream : " << name_.c_str();
os << "ITstream : " << name_.c_str() << ", line ";
if (size())
{
if (begin()->lineNumber() == rbegin()->lineNumber())
{
os << ", line " << begin()->lineNumber() << ", ";
}
else
os << tokenList::first().lineNumber();
if (tokenList::first().lineNumber() < tokenList::last().lineNumber())
{
os << ", lines " << begin()->lineNumber()
<< '-' << rbegin()->lineNumber() << ", ";
os << '-' << tokenList::last().lineNumber();
}
}
else
{
os << ", line " << lineNumber() << ", ";
os << lineNumber();
}
os << ", ";
IOstream::print(os);
}
......
......@@ -143,16 +143,12 @@ void Foam::IOerror::SafeFatalIOError
std::cerr
<< nl
<< "--> FOAM FATAL IO ERROR:" << nl
<< msg
<< nl
<< msg << nl
<< "file: " << ioStream.name()
<< " at line " << ioStream.lineNumber() << '.'
<< nl << nl
<< " From function " << functionName
<< nl
<< " at line " << ioStream.lineNumber() << '.' << nl << nl
<< " From function " << functionName << nl
<< " in file " << sourceFileName
<< " at line " << sourceFileLineNumber << '.'
<< std::endl;
<< " at line " << sourceFileLineNumber << '.' << std::endl;
std::exit(1);
}
}
......@@ -264,28 +260,41 @@ void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
if (!os.bad())
{
os << nl;
if (includeTitle)
if (includeTitle && !title().empty())
{
os << title().c_str() << nl;
}
os << message().c_str() << nl << nl;
os << "file: " << ioFileName().c_str();
const bool hasFile = !ioFileName().empty();
if (ioStartLineNumber() >= 0 && ioEndLineNumber() >= 0)
if (hasFile)
{
os << " from line " << ioStartLineNumber()
<< " to line " << ioEndLineNumber() << '.';
}
else if (ioStartLineNumber() >= 0)
{
os << " at line " << ioStartLineNumber() << '.';
os << "file: " << ioFileName().c_str();
if (ioStartLineNumber() >= 0)
{
if (ioStartLineNumber() < ioEndLineNumber())
{
os << " from line " << ioStartLineNumber()
<< " to line " << ioEndLineNumber() << '.';
}
else
{
os << " at line " << ioStartLineNumber() << '.';
}
}
}
if (IOerror::level >= 2 && sourceFileLineNumber())
{
os << nl << nl
<< " From function " << functionName().c_str() << nl
if (hasFile)
{
os << nl << nl;
}
os << " From function " << functionName().c_str() << nl
<< " in file " << sourceFileName().c_str()
<< " at line " << sourceFileLineNumber() << '.';
}
......
......@@ -84,10 +84,10 @@ public:
// Constructors
//- Construct from title string
error(const string& title);
explicit error(const string& title);
//- Construct from dictionary
error(const dictionary& errDict);
explicit error(const dictionary& errDict);
//- Construct as copy
error(const error& err);
......@@ -190,15 +190,15 @@ public:
operator dictionary() const;
//- Helper function to print a stack (if OpenFOAM IO not yet
// initialised)
//- Helper function to print a stack,
//- used when OpenFOAM IO not yet initialised.
static void safePrintStack(std::ostream& os);
//- Helper function to print a stack
static void printStack(Ostream& os);
//- Exit : can be called for any error to exit program.
// Prints stack before exiting.
// Prints stack before exiting, when FOAM_ABORT is on.
void exit(const int errNo = 1);
//- Abort : used to stop code for fatal errors.
......@@ -277,7 +277,7 @@ public:
const char* functionName,
const char* sourceFileName,
const int sourceFileLineNumber,
const IOstream&
const IOstream& ioStream
);
//- Convert to OSstream
......@@ -287,17 +287,18 @@ public:
const char* functionName,
const char* sourceFileName,
const int sourceFileLineNumber,
const dictionary&
const dictionary& dict
);
//- Print basic message and exit. Uses cerr if streams not constructed
// yet (at startup). Use in startup parsing instead of FatalError.
//- Print basic message and exit.
// Uses cerr if streams not yet constructed (at startup).
// Use in startup parsing instead of FatalError.
static void SafeFatalIOError
(
const char* functionName,
const char* sourceFileName,
const int sourceFileLineNumber,
const IOstream&,
const IOstream& ioStream,
const string& msg
);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -69,8 +69,7 @@ Foam::OSstream& Foam::messageStream::masterStream(const label communicator)
{
if (UPstream::warnComm != -1 && communicator != UPstream::warnComm)
{
Pout<< "** messageStream with comm:" << communicator
<< endl;
Pout<< "** messageStream with comm:" << communicator << endl;
error::printStack(Pout);
}
......@@ -132,20 +131,23 @@ Foam::OSstream& Foam::messageStream::operator()
{
OSstream& os = operator OSstream&();
os << endl
<< " From function " << functionName << endl
os << nl
<< " From function " << functionName << nl
<< " in file " << sourceFileName
<< " at line " << sourceFileLineNumber << endl
<< " at line " << sourceFileLineNumber << nl
<< " Reading " << ioFileName;
if (ioStartLineNumber >= 0 && ioEndLineNumber >= 0)
{
os << " from line " << ioStartLineNumber
<< " to line " << ioEndLineNumber;
}
else if (ioStartLineNumber >= 0)
if (ioStartLineNumber >= 0)
{
os << " at line " << ioStartLineNumber;
if (ioStartLineNumber < ioEndLineNumber)
{
os << " from line " << ioStartLineNumber
<< " to line " << ioEndLineNumber;
}
else
{
os << " at line " << ioStartLineNumber;
}
}
os << endl << " ";
......@@ -201,21 +203,21 @@ Foam::messageStream::operator Foam::OSstream&()
const bool collect = (severity_ == INFO || severity_ == WARNING);
// Report the error
if (!Pstream::master() && collect)
if (collect && !Pstream::master())
{
return Snull;
}
else
{
if (title().size())
if (!title().empty())
{
if (Pstream::parRun() && !collect)
if (collect || !Pstream::parRun())
{
Pout<< title().c_str();
Sout<< title().c_str();
}
else
{
Sout<< title().c_str();
Pout<< title().c_str();
}
}
......@@ -231,13 +233,13 @@ Foam::messageStream::operator Foam::OSstream&()
}
}
if (Pstream::parRun() && !collect)
if (collect || !Pstream::parRun())
{
return Pout;
return Sout;
}
else
{
return Sout;
return Pout;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment