test-fullautomation / python-jsonpreprocessor

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

Error message (6) #236

Open HolQue opened 2 months ago

HolQue commented 2 months ago

JSON code:

"testlist" : ["A", "B", "C", "D"],
"param2"   : ${testlist}[X]

causes:

'Invalid syntax! A sub-element in ${testlist}[X] has to enclosed in quotes.'

That's wrong. Correct would be something like: "list indices must be integers"

For example, this works:

"intval"   : 1,
"testlist" : ["B", 2],
${testlist}['${intval}'] : 4

Outcome:

'Could not set variable '${testlist}['${intval}']' with value '4'! Reason: list indices must be integers or slices, not str'

Addendum: In between it has been decided to block slicing. Therefore we cannot suggest to use slices. The part "or slices" has to be removed from error message.

HolQue commented 1 month ago

Addendum:

In between the behavior changed.

"testlist" : ["A", "B", "C", "D"],
"param2"   : ${testlist}[X]

now causes:

{'param2': "['A', 'B', 'C', 'D'][X]", 'testlist': ['A', 'B', 'C', 'D']}

instead of:

'Invalid syntax! A sub-element in ${testlist}[X] has to enclosed in quotes.'

But the new result is not better than the old one. It makes no sense to return the entire expression as string, with ${testlist} resolved.

Nevertheless: The previous error message is still implemented:

errorMsg = f"Invalid syntax! A sub-element in {sInput.strip()} has to enclosed in quotes."

But I cannot find this error message in any of my log files. Is this still a valid use case? Or in other words: How must a JSON code look like to cause this error?

namsonx commented 4 days ago

Hello Holger,

Thank you for your finding! This is my mistake while improving JsonPreprocessor code. I created the small change to fix it on stabi branch (commit ID: eeaec86fbc)

Thank you, Son

HolQue commented 2 days ago

Hi Son,

my question in

https://github.com/test-fullautomation/python-jsonpreprocessor/issues/236#issuecomment-2052070838

is still open.

I would like to know about a use case that causes this error message:

errorMsg = f"Invalid syntax! A sub-element in {sInput.strip()} has to enclosed in quotes."