No error when forgetting ¨;¨ in particle forces in the kinematicCloudProperties file
I made the really stupid mistake of forgetting the semicolon at the end of a particle force in the kinematicCloudProperties file.
WenYuDragForce { alphac alpha.water }
Because the statement is not ended, the next particle forces are not read in, which lead to really weird results. However, there is no warning of error. In many other input dictionaries the solver crashes because the next line is not read in.
I get that the user is responsible in the end for the input. However, in many other cases we are helped by errors and warnings. Therefore this mistake slipped by me. Would there be an easy fix to check this and give an error? I think this would be a nice safety feature. However, I can imagine that it would be too much work to prevent this kind of mistakes.
No child items are currently assigned. Use child items to break down this issue into smaller parts.
Link issues together to show that they're related. Learn more.
Activity
- Mark OLESEN assigned to @mark
assigned to @mark
- Maintainer
Some interesting ideas that you raise.
Properly handling bad input is indeed a vexing task. With issue #510 (closed) (leading to change
ddfbc7ed9e210143bf58a868ade9d49f64d02336) we tried to trap some possible cases. With change 13f04876894ac8a2132c5661c59de09bbc4e4e4c I started something similar for command-line entries - I didn't like the idea that trailing input rubbish should go undetected.For your issue, the problem is how we handle the dictionary input entries that are improperly terminated, or perhaps have additional trailing junk. In most cases we simply say something like this:
someType(dict.lookup("type"));
The dictionary
lookup()
returns a list of entry tokens represented as anITstream
(an input token stream) that allows someType to read the word, leaving the stream positioned for the next possible read. This also means that things like the following work:div(phi,U) bounded Gauss linearUpwindV grad(U);
To catch trailing rubbish, we could have something like
lookupOne()
which would assert that the token stream has exactly one token and make loads of changes in the code, but this concept would start to fall apart if we are processing something slightly more complex. Eg,fields (U T p);
where a single token assert isn't going to work. So I think we can forget this idea.
For your issue, we have the '}' being add into the previous token stream. So that you essentially have
alphac alpha.water }
plus pretty much the entire balance of your dictionary as being the entry.
Having a '}' in the entry is perfectly OK, since we could have sub dictionaries etc. Maybe a reasonable ad hoc solution might be to trap unbalanced pairs of
{
and}
?Can we think of cases where this would a cause a false positive?
- Author Maintainer
Thank you for taking an interest in this case. I think many compilers check for a balance in
{
and}
and I cannot think of a case where you would not want a closing bracket. I think this would be good solution.Another idea is to check if there is a semicolon between an entry the closing
}
If there no semicolon there, you also know the location of the missing semicolon and could give an exact error message. Could this leads to weird behaviour?By Bas Nieuwboer on 2018-03-12T09:22:30 (imported from GitLab project)
- Maintainer
- Maintainer
The extra checks for mismatching the shapes of brackets (eg, `{)' mismatch) seems nice enough, but probably have to tackle it with two depth counters instead. I don't think it will manage the following at all:
some ( ( test ) }
since the first closing
)
resets the startBlock.Edited by Mark OLESEN - Mark OLESEN mentioned in commit b1d2f466c12445cd71f8709fece024c9f348c317
mentioned in commit b1d2f466c12445cd71f8709fece024c9f348c317
- Mark OLESEN mentioned in issue #843 (closed)
mentioned in issue #843 (closed)
- Maintainer
How about enforcing reading all optional entries to eof (i.e. enforcing the token stream to be one entry only)
See attached test app. Run on cavity case inside (with error in system/controlDict).
- Maintainer
This obviously won't cover everything, but is a good start. I'll add it in.
- Maintainer
Please check since it should only be applied to optional entries. I have not run anything else but my little test.
- Maintainer
Taken yet another look, and this actually looks like a way to move forward - albeit still a long way. Your idea is currently just for optional entries (and lookupType, which only occurs once in the code).
If we have a
get<T>
method with the same idea aslookupType<T>
- transforming an entry to a single value and checking for excess tokens, we easily replace these types of constructions:var1_(readScalar(dict.lookup("key1"))) var2_(readLabel(dict.lookup("key2")))
with
var1_(dict.get<scalar>("key1")) var2_(dict.get<label>("key2"))
Which probably means that these will be the rule.
Edited by Mark OLESEN - Mark OLESEN mentioned in commit e48dd3c1eaccc7e7816fe40aee81d59b4299531e
mentioned in commit e48dd3c1eaccc7e7816fe40aee81d59b4299531e
- Mark OLESEN mentioned in commit 84fcc7324e342c3e13f9d29d23af94703d7e214c
mentioned in commit 84fcc7324e342c3e13f9d29d23af94703d7e214c
- Mark OLESEN mentioned in commit 2549500d090d30d972ba193af6db9a1a32d3e7ee
mentioned in commit 2549500d090d30d972ba193af6db9a1a32d3e7ee
- Maintainer
Master only dictionary reading does not transfer line numbers and file name.
E.g. master processor (upon error) correctly prints
0] entry 'order' has 2 excess tokens, near line: 25 dictionary: "/hosts/punwor073/home/pss/projects/GIT/dictionaryInputChecks/system/decomposeParDict.optional"
slave processors print
entry 'order' has 2 excess tokens, near line: 0 dictionary: "IOstream"
- Mark OLESEN mentioned in commit bb2b90ef27c4a8831dcfa4f939f06e7657172f2f
mentioned in commit bb2b90ef27c4a8831dcfa4f939f06e7657172f2f
- Maintainer
@mark: Any particular reason why they are not detected here? (as not optional entries?)
Is it that the bracket count should be zero at end of dictionary? Or only at end of IOdictionary?
- Maintainer
Just looking into this - bracket counting was only for primitive entries...
Edited by Mark OLESEN - Maintainer
The issue reported related to the handling of a missing brace or an extra brace. The problem arises from how
entry::New
is being used to parse dictionary entries. We need to have a check similar to the Istream::readEndList treatment - to manage expected values. - Mark OLESEN mentioned in commit 79fee8f7b58e8c4d590ffdc944f93fe5d8b76ab2
mentioned in commit 79fee8f7b58e8c4d590ffdc944f93fe5d8b76ab2
- Maintainer
- Mark OLESEN mentioned in commit 8e317427e8c0ca5ce29a77145c93f26dc2a7ebf8
mentioned in commit 8e317427e8c0ca5ce29a77145c93f26dc2a7ebf8
- Mark OLESEN mentioned in commit 77420591399d4c8526ebea3d434ec757c7938260
mentioned in commit 77420591399d4c8526ebea3d434ec757c7938260
- Mark OLESEN mentioned in commit 1ca45420f4beafc12e68101b12472aac3598ef05
mentioned in commit 1ca45420f4beafc12e68101b12472aac3598ef05
- Mark OLESEN mentioned in commit af7fd85fb9849ef94770e71b6fa1bbdaf50a3a81
mentioned in commit af7fd85fb9849ef94770e71b6fa1bbdaf50a3a81
- Mark OLESEN mentioned in commit f057060dc29940dae7b9564b2ac71877ed19a75b
mentioned in commit f057060dc29940dae7b9564b2ac71877ed19a75b
- Mark OLESEN mentioned in commit 143936726a89ca8f0ea193da615fa93b514d86b7
mentioned in commit 143936726a89ca8f0ea193da615fa93b514d86b7
- Mark OLESEN mentioned in commit d8c49fc8c73a1a80c9f6170d9fe8854050851099
mentioned in commit d8c49fc8c73a1a80c9f6170d9fe8854050851099
- Mark OLESEN mentioned in commit 532a3d3c9ddcab70eae2c9835a89797b1f8f41c2
mentioned in commit 532a3d3c9ddcab70eae2c9835a89797b1f8f41c2
- Mark OLESEN mentioned in commit f2049c5846938ce9849732263d541380bb81478b
mentioned in commit f2049c5846938ce9849732263d541380bb81478b
- Mark OLESEN mentioned in issue #1033 (closed)
mentioned in issue #1033 (closed)
- Mark OLESEN mentioned in commit 392ef54c35db01592167b5484a46a1b9e55ad1b7
mentioned in commit 392ef54c35db01592167b5484a46a1b9e55ad1b7
- Mark OLESEN mentioned in commit 45c8503c1f9316b48e2ff8f6e8aed35448ee180a
mentioned in commit 45c8503c1f9316b48e2ff8f6e8aed35448ee180a
- Mark OLESEN mentioned in commit efe026910e3c7b79c4a56d297b20d0111fe7f9fa
mentioned in commit efe026910e3c7b79c4a56d297b20d0111fe7f9fa
- Mark OLESEN mentioned in commit e80be5840ae122973e5706631d0efc0c02614f6c
mentioned in commit e80be5840ae122973e5706631d0efc0c02614f6c
- Mark OLESEN mentioned in commit fdb5ae09bf217218545a90d1fe8f3c0e779bd310
mentioned in commit fdb5ae09bf217218545a90d1fe8f3c0e779bd310
- Mark OLESEN mentioned in commit 1cc0e66f0c22366d02f320d853f4e958a2a37a02
mentioned in commit 1cc0e66f0c22366d02f320d853f4e958a2a37a02
- Mark OLESEN mentioned in commit 9a5038a8ae9b79b1be56e40f01923e138e8af01d
mentioned in commit 9a5038a8ae9b79b1be56e40f01923e138e8af01d
- Mark OLESEN closed
closed