ENH: add line number for dictionary getCheck errors

This commit is contained in:
Mark Olesen
2020-03-11 19:54:51 +01:00
parent 6ab699633d
commit a18617bbd1
4 changed files with 17 additions and 10 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd. Copyright (C) 2017-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -352,6 +352,7 @@ int main(int argc, char *argv[])
( (
"good 3.14159;\n" "good 3.14159;\n"
"negative -3.14159;\n" "negative -3.14159;\n"
"neg2 -3.14159;\n"
"empty;\n" "empty;\n"
// "bad text;\n" // always fails // "bad text;\n" // always fails
// "bad 3.14159 1234;\n" // fails for readScalar // "bad 3.14159 1234;\n" // fails for readScalar
@ -386,6 +387,7 @@ int main(int argc, char *argv[])
try_getCheckScalar(dict2, "good", scalarRange::gt0()); try_getCheckScalar(dict2, "good", scalarRange::gt0());
try_getCheckScalar(dict2, "negative", scalarRange::gt0()); try_getCheckScalar(dict2, "negative", scalarRange::gt0());
try_getCheckScalar(dict2, "neg2", scalarRange::gt0());
try_getCheckScalar(dict2, "good", greaterOp1<scalar>(0)); try_getCheckScalar(dict2, "good", greaterOp1<scalar>(0));
try_getCheckScalar(dict2, "negative", greaterOp1<scalar>(0)); try_getCheckScalar(dict2, "negative", greaterOp1<scalar>(0));

View File

@ -338,7 +338,11 @@ void Foam::dictionary::checkITstream
} }
void Foam::dictionary::raiseBadInput(const word& keyword) const void Foam::dictionary::raiseBadInput
(
const ITstream& is,
const word& keyword
) const
{ {
// Can use FatalIOError instead of SafeFatalIOError // Can use FatalIOError instead of SafeFatalIOError
// since predicate checks are not used at the earliest stages // since predicate checks are not used at the earliest stages
@ -347,10 +351,11 @@ void Foam::dictionary::raiseBadInput(const word& keyword) const
"", // functionName "", // functionName
"", // sourceFileName "", // sourceFileName
0, // sourceFileLineNumber 0, // sourceFileLineNumber
*this // ios this->name(), // ioFileName
is.lineNumber(), // ioStartLineNumber
-1 // ioEndLineNumber
) )
<< "Entry '" << keyword << "' with invalid input in dictionary " << "Entry '" << keyword << "' with invalid input" << nl
<< name() << nl << nl
<< exit(FatalIOError); << exit(FatalIOError);
} }

View File

@ -357,7 +357,7 @@ private:
//- Emit IOError about bad input for the entry //- Emit IOError about bad input for the entry
void raiseBadInput(const word& keyword) const; void raiseBadInput(const ITstream& is, const word& keyword) const;
//- The case-relative dictionary name. Uses FOAM_CASE //- The case-relative dictionary name. Uses FOAM_CASE
fileName relativeName(const bool caseTag=false) const; fileName relativeName(const bool caseTag=false) const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd. Copyright (C) 2017-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -229,7 +229,7 @@ T Foam::dictionary::getCheckOrDefault
if (!pred(val)) if (!pred(val))
{ {
raiseBadInput(keyword); raiseBadInput(is, keyword);
} }
return val; return val;
@ -284,7 +284,7 @@ T Foam::dictionary::getCheckOrAdd
if (!pred(val)) if (!pred(val))
{ {
raiseBadInput(keyword); raiseBadInput(is, keyword);
} }
return val; return val;
@ -362,7 +362,7 @@ bool Foam::dictionary::readCheck
if (!pred(val)) if (!pred(val))
{ {
raiseBadInput(keyword); raiseBadInput(is, keyword);
} }
return true; return true;