test-fullautomation / python-jsonpreprocessor

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

'parameter' vs. 'variable' #257

Open HolQue opened 1 month ago

HolQue commented 1 month ago

In error messages sometimes the term 'variable' is used, sometimes the term 'parameter'. In some cases both of them:

'Could not set variable '${keyP.${indexP}}' with value 'newvalue'! Reason: 'str' object does not support item assignment'
'The variable '${dictP}['0']' is not available!'
'Found expression '${dictP}' with at least one parameter of composite data type ('${dictP}' is of type <class 'dict'>). Because of this expression is the name of a parameter, only simple data types are allowed to be substituted inside.'
'Invalid index or dictionary key in parameter '${dictP}[${dictP}]'. The datatype of variable '${dictP}' have to 'int' or 'str'.'
'Invalid parameter format in line: "par${1}am2" : "123"'
'Invalid syntax: Found index or sub-element inside curly brackets in the parameter '${dictP[${dictP}]}''
'The implicit creation of data structures based on parameter is not supported. New parameter '0['0']' could not be created by the expression '${indexP}['${indexP}']''

Does this usage currently follow a certain rule? What is the difference between 'parameter' and 'variable'? In internet a lot of discussions about this question can be found; also definitions. Sometimes very academic.

Can we - in the context of the JsonPreprocessor - take over these definitions? Or in other words: Does it make sense for the JsonPreprocessor to distinguish between a variable and a parameter?

My personal feeling is that it's better to use only one of these terms.

And because of I feel really uncomfortable with this topic in general, I would try to avoid the term 'parameter' and 'variable' as much as possible ;-)

For example:

Instead of: 'Could not set variable '${keyP.${indexP}}' with value 'newvalue'! Reason: 'str' object does not support item assignment'

Better: 'str' object does not support item assignment' (expression: '${keyP.${indexP}}').

Instead of: 'Invalid index or dictionary key in parameter '${dictP}[${dictP}]'. The datatype of variable '${dictP}' have to 'int' or 'str'.'

Alternative version: Key error: Dictionary keys have to be of type int or str (expression: '${dictP}[${dictP}]').

Instead of: 'Invalid syntax: Found index or sub-element inside curly brackets in the parameter '${dictP[${dictP}]}''

Alternative version: 'Invalid syntax: Found index or sub-element inside curly brackets (expression: '${dictP[${dictP}]}')'

Current version: 'The implicit creation of data structures based on parameter is not supported. New parameter '0['0']' could not be created by the expression '${indexP}['${indexP}']''

Alternative version: The implicit creation of data structures based on parameters is not supported (expression: '${testdict.B}['${name}']'). See also https://github.com/test-fullautomation/python-jsonpreprocessor/issues/237

What do you think?

HolQue commented 1 month ago

The rework of the error messages also includes to have a unique structure in mind. This also eases the readability and understandability.

At first the pure error, e.g.: 'str' object does not support item assignment' After this: line or expression, where the error happens (if detectable) Finally: impact or further details or hints about how to solve (but only if it's really helpful or required to understand the meaning of the error), e.g:

test-fullautomation commented 1 month ago

Hi Holger, usually the jpp files will be used to configure the behavior of any code. Therefore from my point of view we define parameters., => we shall use nowhere the word variable, but instead parameter / parameters.

w.r.t error messages: We can do it this or that way. Only important is, that all error messages have a unified structure.

Proposals like e.g. below are fine for me. It avoids the word "parameter", has the same message content and is shorter. Instead of: 'Invalid index or dictionary key in parameter '${dictP}[${dictP}]'. The datatype of variable '${dictP}' have to 'int' or 'str'.'

Alternative version: Key error: Dictionary keys have to be of type int or str (expression: '${dictP}[${dictP}]').

Regards, Thomas

test-fullautomation commented 1 month ago

Hi @namsonx , plesae consider this from now onwards for all your activities. Thank you, Thomas