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