diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 219b4ee988..376c46f1d9 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -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 << tokenList::first().lineNumber(); + + if (tokenList::first().lineNumber() < tokenList::last().lineNumber()) { - os << ", line " << begin()->lineNumber() << ", "; - } - else - { - os << ", lines " << begin()->lineNumber() - << '-' << rbegin()->lineNumber() << ", "; + os << '-' << tokenList::last().lineNumber(); } } else { - os << ", line " << lineNumber() << ", "; + os << lineNumber(); } + os << ", "; + IOstream::print(os); } diff --git a/src/OpenFOAM/db/error/IOerror.C b/src/OpenFOAM/db/error/IOerror.C index 3b52d33293..55cf4802ad 100644 --- a/src/OpenFOAM/db/error/IOerror.C +++ b/src/OpenFOAM/db/error/IOerror.C @@ -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() << '.'; } diff --git a/src/OpenFOAM/db/error/error.H b/src/OpenFOAM/db/error/error.H index 102a555ab5..8dc2e6cff2 100644 --- a/src/OpenFOAM/db/error/error.H +++ b/src/OpenFOAM/db/error/error.H @@ -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 ); diff --git a/src/OpenFOAM/db/error/messageStream.C b/src/OpenFOAM/db/error/messageStream.C index a0cff358e4..ce225134c8 100644 --- a/src/OpenFOAM/db/error/messageStream.C +++ b/src/OpenFOAM/db/error/messageStream.C @@ -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) + 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 << " "; @@ -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; } } }