Skip to content

lib/addoninfo.cpp: When loading a JSON addon, test 'script' key.#5797

Merged
firewave merged 1 commit into
cppcheck-opensource:mainfrom
Rail-Connected:pullreq4
Dec 25, 2023
Merged

lib/addoninfo.cpp: When loading a JSON addon, test 'script' key.#5797
firewave merged 1 commit into
cppcheck-opensource:mainfrom
Rail-Connected:pullreq4

Conversation

@mvds00
Copy link
Copy Markdown
Contributor

@mvds00 mvds00 commented Dec 22, 2023

In case a user accidentally uses a wrong JSON file (e.g. naming.json, which is the config file for namingng.py), the code could give a confusing exception. This happens when the key 'script' is not defined as a string.

This is solved by testing the key for existence and type. In case 'script' is not a key or refers to a type other than a string, a clear error is given, stating for example: 'Loading naming.json failed. script must be set to a string value.'

The message is kept in line with other messages. Maybe it can be clarified further, e.g. 'Loading naming.json failed. A key "script" must be set with a string value referring to a Python script.' - in which case the errors relating to other keys may also be clarified.

@firewave
Copy link
Copy Markdown
Collaborator

Thanks for your contribution.

Please add a unit test for this. This applies to all PRs in general (at least in my book).

Unfortunately I am currently not able to follow up on things and I am not able to tell when that will be the case again. So if somebody else merges them there might quite some feedback from me way after this has been accepted.

FYI I had this change locally with a general refactoring of the JSON reading but I hadn't completed as tests yet and wasn't too happy with some of the code.

… of script key.

In case a user accidentally uses a wrong JSON file (e.g. naming.json, which is
the config file for namingng.py), the code could give a confusing exception.
This happens when the key 'script' is not defined as a string.

This is solved by testing the key for existence and type. In case 'script' is
not a key or refers to a type other than a string, a clear error is given,
stating for example: 'Loading naming.json failed. script must be set to a
string value.'

A unit test is included for this specific error.
@mvds00
Copy link
Copy Markdown
Contributor Author

mvds00 commented Dec 25, 2023

Please add a unit test for this. This applies to all PRs in general (at least in my book).

done.

@firewave firewave merged commit 403e7f1 into cppcheck-opensource:main Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants