Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent errors in the json encode process #592

Merged
merged 1 commit into from
Jun 26, 2024
Merged

prevent errors in the json encode process #592

merged 1 commit into from
Jun 26, 2024

Conversation

nullvariable
Copy link
Contributor

adds an exception handler to the json.encode options so that the parser prints the name of the function or the reason it couldn't parse a key instead of crashing out.

Example before:

SCRIPT ERROR: type 'function' is not supported by JSON
[       script:test] 
[       script:test] > libPrint (@ox_lib/imports/print/server.lua:33)
[       script:test] > info (@ox_lib/imports/print/server.lua:42)
[       script:test] > ref (@test/server/test.lua:27)

After:

script:test] [test] [INFO] {
[       script:test]     "number": 30,
[       script:test]     "string": "Los Angeles",
[       script:test]     "fthis": "function: 0000020E8ABDD3F0"
[       script:test] }

Optionally returning nil instead of reason would still throw an error, while allowing objects with functions on them to be dumped in without needing to remove them first.

adds an exception handler to the json.encode options so that the parser prints the name of the function or the reason it couldn't parse a key instead of crashing out.

Example before:
SCRIPT ERROR: type 'function' is not supported by JSON
[       script:test] 
[       script:test] > libPrint (@ox_lib/imports/print/server.lua:33)
[       script:test] > info (@ox_lib/imports/print/server.lua:42)
[       script:test] > ref (@test/server/test.lua:27)

After:
script:test] [test] [INFO] {
[       script:test]     "number": 30,
[       script:test]     "string": "Los Angeles",
[       script:test]     "fthis": "function: 0000020E8ABDD3F0"
[       script:test] }
@thelindat thelindat merged commit cdf840f into overextended:master Jun 26, 2024
@nullvariable nullvariable deleted the patch-1 branch June 29, 2024 11:40
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