test-fullautomation / python-jsonpreprocessor

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

Invalid assignments in JSON parameter configuration file #67

Closed HolQue closed 8 months ago

HolQue commented 1 year ago

Based on

https://github.com/test-fullautomation/python-jsonpreprocessor/issues/66

I checked further use cases.

[1]

"teststring_variant" : "${a.1,b.2;c.3"

Error message: list index out of range

This error message seems to point to the origin of the problem, but in this case the error message does not help the user. It's irrelevant for him that internally a list access went wrong. Maybe it's possible to improve the error message. In case of dollar operator and curly brackets have a syntactical meaning inside quotes, then the example above is a syntax violation, and not a list index problem. Maybe you count the number of opened and closed curly brackets inside a string. In case of different numbers: syntax error!

[2]

How to mask those special characters?

I tried: "\$\{a.1,b.2;c.3"

This is not accepted: Invalid \escape: line 10 column 51 (char 390)'

But I am not sure: Is this allowed?

[3]

This is accepted: "$$${a$}.1,b.2;c.3"

With meaningful error message: The variable '${a$}' is not available!

Curious, this is not accepted: "$$${a}.1,b.2;c.3"

Error message: Expecting ',' delimiter: line 10 column 54 (char 393)'

This does not help the users. Why not the same error message like in the example before (missing variable ${a})?

[4]

Robot Framework knows further operators do define values, e.g.: &.

"teststring_variant" : "$$ &{a$}.1,b.2;c.3"

Error message: Variable '${teststring_variant}' not found.

Astonishing. Seems that '&' is not allowed inside strings, or harms the parser. But it is unfavorable, that only the aftereffect (variable not found) is mentioned in the error message, but not the root cause (something invalid used or syntax violation within the assigned value).

Is it possible to detect the root cause and improve the error message?

HolQue commented 1 year ago

Addendum:

[1] - [3] are error scenarios, that are detected at the very beginning of computation. Tests are not executed. Test result is UNKNOWN. This is like expected.

[4] is not an issue of the preprocessor! Maybe also not an issue of the testsuites management. The robot test is executed. It seems to me that the error happened anywhere else.

The string "$$ &{a$}.1,b.2;c.3" is accepted by preprocessor and testsuites management. That's fine. But there must be any position in the code where this string is handed over to the Robot Framework. Within Robot Framework the '&' has a syntactical meaning. Because of this something went wrong with the assignment of this string to variable "teststring_variant". With the outcome, that this variable does not exist. We have to find this position, where '&' harms the computation. Maybe then we have a chance to improve the behavior of the framework. Only telling that something does not exist - without any further hints about possible root causes - is not really user friendly.

test-fullautomation commented 1 year ago

Hi Holger, very good! We need to sit together to define the requirement. Based on this I will create a task/tasks which are then base for a SelfTest extension. Thank you, Thomas

HolQue commented 1 year ago

Addendum:

Masked backslashes disappear in console and log output:

Defined: "a\\b" Output: "ab"

But expected: "a\b"

Addendum: This is tested with Testsuites Management is involved! And it seems that the Testsuites Management causes the error. When I use the pure JsonPreprocessor, then the input

"a\\b"

causes the following proper output: "a\b".

test-fullautomation commented 1 year ago

Hi Holger,

good luck! You sucessfully opened a can of worms. To make this properly running we need first to define what we want. Then we need to check the whole chain where our defined rules are violated.

I know from TML how difficult it is to stabilize this.

Thank you, Thomas

namsonx commented 10 months ago

Hello Holger,

I implemented change for this ticket and push to the stabi branch (namsonx/task/stabi_branch) with the change the cases [1], [3] will show the error log: Invalid nested parameter format in line: "teststring_variant" : "${a.1,b.2;c.3" and Invalid nested parameter format in line: "teststring_variant" : "$$${a$}.1,b.2;c.3"

Thank you, Son

test-fullautomation commented 8 months ago

Hi @namsonx , what is the status of this ticket? Thank you, Thomas

HolQue commented 8 months ago

Retest successful.

All code combinations listed above, either are accepted properly or cause meaningful error messages. Ticket can be closed.