test-fullautomation / python-jsonpreprocessor

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

Error handling improvements (1) #207

Closed HolQue closed 2 months ago

HolQue commented 4 months ago

I have some doubts about the outcome and the error messages caused by the following code examples:

(1) Negative integer applied to a string:

"param1" : "value",
"param2" : ${param1}[-1]

Result:

Error: 'Invalid nested parameter format: ${param1}[-1] - The double quotes are missing!!!'!

Therefore with double quotes:

"param1" : "value",
"param2" : "${param1}[-1]"

Result:

{'param1': 'value', 'param2': 'e[-1]'}

(2) The same with a list:

"testlist" : [1,2,3],
"value"    : ${testlist}[-1]

Result:

Error: 'Invalid nested parameter format: ${testlist}[-1] - The double quotes are missing!!!'!

Therefore with double quotes:

"testlist" : [1,2,3],
"value"    : "${testlist}[-1]"

Result:

{'testlist': [1, 2, 3], 'value': '3[-1]'}

(3) Same with pair of empty square brackets:

"param1" : "value",
"param2" : ${param1}[]

Error: 'Invalid nested parameter format: ${param1}[] - The double quotes are missing!!!'!

"param1" : "value",
"param2" : "${param1}[]"

Error: 'The variable '${param1}[]' is not available!'!

"testlist" : [1,2,3],
"value"    : ${testlist}[]

Error: 'Invalid nested parameter format: ${testlist}[] - The double quotes are missing!!!'!

"testlist" : [1,2,3],
"value"    : "${testlist}[]"

Error: 'The variable '${testlist}[]' is not available!'!

In all cases above the square brackets are part of a dollar operator expression containing an existing parameter. Therefore the brackets have a syntactical meaning. Therefore strict syntax rules can be applied to them:

  1. Negative integers are not allowed inside square brackets (would be a slicing issue). At least invalid mixed results like '3[-1]' must not occur.
  2. A pair of square brackets must not be empty

I would assume now that it is possible to provide an error message like:

Expression '${testlist}[]' cannot be evaluated. Reason: Empty pair of square brackets detected.

This would be more helpful than simply telling that a variable does not exist.

namsonx commented 3 months ago

Hello Hogler,

Thank you for your findings and suggestion! This ticket was solved on stabi branch.

Thank you, Son

HolQue commented 3 months ago

Retest successful. Issue can be closed.

test-fullautomation commented 2 months ago

integrated in RobotFramework AIO 0.11.0