Jellycuts / Jellycuts-Issues

A public issue tracker for the Jellycuts iOS app.
25 stars 0 forks source link

JSON validation fails during compilation for JSON variables with (unquoted) number fields #136

Open twilsonco opened 10 months ago

twilsonco commented 10 months ago

In my first attempt at rewriting a ShortCut as a JellyCut (this ShortCut for ChatGPT API use), I've encountered a bug with JellyCuts validation of JSON arguments, which is rejecting valid JSON strings that contain (in this case) number fields (unquoted), causing compilation to fail with "Compilation Error on line 6: Unable to find valid JSON", but only when the JSON being evaluated is from an existing Dictionary variable.

This validation is performed, for example, when using the dictionary() or downloadURL() functions, both of which take JSON variable or JSON string as arguments.

Interestingly, it won't reject the valid JSON string if it's hardcoded, so the following JellyCut code compiles and the resulting shortcut works:

import Shortcuts
#Color: red, #Icon: shortcuts 

dictionary(json: {"string": "value", "number": 1.0}) >> TestDict
showResult(text: "${TestDict}")

But, when the JSON being evaluated is a variable, the validation fails. So this code fails:

import Shortcuts
#Color: red, #Icon: shortcuts 

dictionary(json: {"string": "value", "number": 1.0}) >> TestDict
showResult(text: "${TestDict}")
dictionary(json: "${TestDict}") >> TestDict2
showResult(text: "${TestDict2}")

giving the error: "Compilation Error on line 6: Unable to find valid JSON" which is this line:

dictionary(json: "${TestDict}") >> TestDict2

Version/Device info. iPhone Mini 13, iOS 17.1.1, JellyCuts v1.4.1(5)

Also posted in Discord #issues-bugs

bad_json.jelly.txt good_json.jelly.txt

twilsonco commented 10 months ago

Cloned Open-JellyCuts (along with submodules), and searched for the error thrown above Unable to find valid JSON but it doesn't come up. I have zero experience with Swift so it'll take some digging before I can make much progress. Guess I'd start here? CleanShot 2023-11-25 at 16 41 44

ActuallyTaylor commented 10 months ago

Thank you for the comprehensive review of the issue! Right now, JSON usage in the App Store version is very finicky. The Open-Jellycuts version fairs much better but still has its own issues.

As for the issue you are seeing, from what I can tell, it is not a currently supported use case.

But, when the JSON being evaluated is a variable, the validation fails. So this code fails: dictionary(json: "${TestDict}") >> TestDict2

When the above code is compiled, the Jelly compiler will not paste the value of the dictionary in to validate it as a string. I believe this bug appeared when I reworked how variables can be typed out, which lost the ability to use them as dictionaries. As of right now, there is not yet a way to fix this on the App Store version. I would gladly add you to the TestFlight version, which is where I will focus future fixes.

ActuallyTaylor commented 10 months ago

and searched for the error thrown above Unable to find valid JSON but it doesn't come up

The reason nothing is showing up is that the App Store version is not running the Open-Jellycore parser yet. When I get through finals season, I will be taking a bit to finish up Open-Jellycore / Jellycuts

twilsonco commented 10 months ago

Understood, and thanks for the quick response! I'm relieved to see that development is ongoing, and not at all surprised at the issues due to App Store and other iOS limitations. Not my area of expertise, but I empathize with devs in Apple's ecosystem.

Side note: Now that I see development is an ongoing effort, I'll report another issue I found where foo.get(keys) for a dictionary variable seemed to not be returning a list of keys as expected. In that case an easy work around was to use keysFrom() instead. I'll put together and submit a MWE for that as well. Though I'll wait to confirm it happens with the TestFlight version so that I can include that context with the bug report.

twilsonco commented 10 months ago

Ok, I'm up and running on the TestFlight version (with another purchase of the Pro unlock, you crafty devil!), and the JSON issues aren't alleviated. Now, running a slightly modified example for dictionary() from the docs also fails:

import Shortcuts
#Color: red, #Icon: shortcuts

dictionary(json:{"name":"Taylor"})

Throws (approximately, this is using OCR since I was unable to select text from the console):

0:3 - ERROR (identifier content: (identifier_content)) (parameter_list_item item: (identifier content: (identifier_content))) (ERROR) (parameter_list_item item: (string text: (string_chars))) (ERROR) (parameter_list_item item: (string text: (string_chars))) (string_chars)

  • Check your syntax in the surrounding area.

I'm happy to troubleshoot, if it helps.

Grim73 commented 2 months ago

having the same issue trying to variable-ize my Bearer token in a downloadURL function, I assume this is still a WIP?