test-fullautomation / python-jsonpreprocessor

A preprocessor for json files
Apache License 2.0
2 stars 2 forks source link

Inkonsistent error handling #304

Open HolQue opened 1 month ago

HolQue commented 1 month ago

Some pairs of input and output:

${dictval.${+strval}} : 1
DotDict({'${dictval.${+strval}}': 1})
${dictval.${-strval}} : 2
Error: 'The parameter '${-strval}' is not available!'!
${dictval.${*strval}} : 3
DotDict({'${dictval.${*strval}}': 3})
${dictval.${strval+}} : 4
DotDict({'${dictval.${strval+}}': 4})
${dictval.${strval-}} : 5
Error: 'The parameter '${strval-}' is not available!'!
${dictval.${strval*}} : 6
DotDict({'${dictval.${strval*}}': 6})
${dictval.${strval+++}} : 7
Error: 'multiple repeat at position 25'!
${dictval.${strval/}} : 8
DotDict({'${dictval.${strval/}}': 8})

Some expressions are not resolved properly. The computation deviates. That should be aligned.

Probably related to: https://github.com/test-fullautomation/python-jsonpreprocessor/issues/285 https://github.com/test-fullautomation/python-jsonpreprocessor/issues/206

namsonx commented 3 days ago

Hello Holger,

Thank you for your finding! I implemented this ticket and pushed the change 1d186d1c9d80d9 to the stabi branch.

Now, if there is a special character presenting in parameter name, the error message below will log out: Exception: Expression '${dictval.${strval/}}' cannot be evaluated. Reason: A pair of curly brackets is empty or contains not allowed characters.

Exception: If the operator - places in between like test-var, JPP will handle as normal. In case - places at the beginning or the end of parameter name, then the error message will log out.

If we also block the operator - like other special characters, I will update the implementation. Please give me your opinion?

Thank you, Son

HolQue commented 2 hours ago

Hi Son, hi Thomas,

sorry - but we cannot continue in this way! So many issues about special characters. So many different code examples causing errors. Or is the result correct and it's no error? Difficult to decide for me. In my opinion the root cause is that the requirements are unclear, and also there is no strategy how to implement this topic. What shall be allowed and what shall not be allowed? And especially where are differences w.r.t. allowed/not allowed parameters in JsonPreprocessor and in TestsuitesManagement? Currently I completely have lost the overview. The current situation is confusing.

Please provide a naming convention. Write it down. On a paper. And then find a proper strategy to implement a naming convention check. Then I have a chance to find a proper test strategy.

And I would prefer to do this based on only one issue. All these discussion micro cycles in several different issues is nothing else than wasting time. Still things are not OK.

For example: The first code at the top of this issue

${dictval.${+strval}} : 1

previously caused invalid results

DotDict({'${dictval.${+strval}}': 1})

The result now is:

Error: 'Expression '${dictval.${+strval}}' cannot be evaluated. Reason: A pair of curly brackets is empty or contains not allowed characters.'!

Seems to be OK, but now I make a cross check. I extend the code in the following way (all parameters defined now):

"dictval" : {"A" : 1, "B" : 2},
"+strval" : "A",
${dictval.${+strval}} : 3

With the same outcome:

Error: 'Expression '${dictval.${+strval}}' cannot be evaluated. Reason: A pair of curly brackets is empty or contains not allowed characters.'!

And immediately I see, that the implementation still is not OK. I mentioned this already in so many issues: Either a certain special character is allowed in key names, then the JsonPreprocessor must be able to handle the corresponding parameter. Or the special character is not allowed. In this case I expect a "naming convention" issue. But this I would expect already in the second line

"+strval" : "A",

of the code above.

A "naming convention" error should already be thrown when the parameter is defined, and not when the parameter is used. It makes no sense to accept the second line and then throw an error in the third line. This is too late.