benetech / Imageshare

MIT License
0 stars 0 forks source link

Runtime error on JSON import #240

Closed clapierre closed 4 years ago

clapierre commented 4 years ago

I received the following Runtime error (instead of it being caught and receiving some error message that is meaningful during the JSON import. Attached is the JSON file which caused the problem, I will look into figuring out the exact issue with the file but in any event we shouldn't get a runtime error.

[Fri Aug 14 21:55:10.044397 2020] [php7:error] [pid 6028] [client 66.201.46.82:12786] PHP Fatal error: Uncaught Twig\Error\RuntimeError: Key "new_resources" for array with keys "resources, errors" does not exist. in /nas/content/live/imgsdev/wp-content/plugins/imageshare/templates/settings.twig:7\nStack trace:\n#0 /nas/content/live/imgsdev/wp-content/plugins/timber-library/vendor/twig/twig/src/Environment.php(497) : eval()'d code(47): Twig\Template->getAttribute(Array, 'new_resources', Array)\n#1 /nas/content/live/imgsdev/wp-content/plugins/timber-library/vendor/twig/twig/src/Template.php(455): __TwigTemplate_ce63602b7c52e748883929469ce5312d2837ca54cd70ad1bc16640351e3956f6->doDisplay(Array, Array)\n#2 /nas/content/live/imgsdev/wp-content/plugins/timber-library/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling(Array, Array)\n#3 /nas/content/live/imgsdev/wp-content/plugins/timber-library/vendor/twig/twig/src/Template.php(434): Twig\Template->display(Array)\n#4 /nas/content/live/imgsdev/wp-content/plugins/timber-library/vendor/twig/twig/src/TemplateWrapper.php(47): Twig\Template->render(Ar in /nas/content/live/imgsdev/wp-content/plugins/imageshare/templates/settings.twig on line 7, referer: https://imgsdev.wpengine.com/wp-admin/options-general.php?page=imageshare_settings

PhetSimulations.json.txt

clapierre commented 4 years ago

Well I see that my

resource_featured_image_URI is missing the initial HTTP and linking to our s3 bucket which I forgot my mistake.

ie: ImageshareResourceFiles/PHetSimulations/Forces+and+Motion+Basics.png

instead of:

https://imagesharemvp.s3.amazonaws.com/ImageshareResourceFiles/PHetSimulations/Forces+and+Motion+Basics.png I will add this and see if this fixes the problem

clapierre commented 4 years ago

Fixing the URLs for the Featured Images didn't address the issue. Attached is the updated JSON file. PhetSimulations.json.txt

sinabahram commented 4 years ago

It is important to note that it may be impossible to do this as an update. Remember that the URL composes the hash. This will require, unless if I am mistaken, for you to delete all resources and re-import them. That may also circumvent this runtime error, but I'll let @jkva comment on the runtime error of course.

clapierre commented 4 years ago

So the issue which caused this runtime is that the file_type in the JSON file has a new type "simulation" which is causing this runtime error.

I added a new File Type under Resource Files / Type: Simulation but it seems that isn't hocked up correctly.

the JSON Schema has this "simulation" so I am confused. "type": { "enum": ["2.5d tactile graphic", "3d model", "audio file", "handmade object", "image", "lesson plan", "manipulative", "simulation", "text document", "url", "video"] },

clapierre commented 4 years ago

Ok so I tracked down when the runtime error occurs If the File Type is not in our schema it throws a runtime error instead of informing us of that this file type is unknown.

Also if the accommodation is not in our schema it also throws a runtime error.

Turns out originally I didn't have "simulation" as a file type which caused the error, then once I added this there was a typo in my JSON file for a couple of the resources which has "sonification" misspelled but it threw a runtime error instead of an caught error with some kind of indication that the misspelt accommodation is in error.

jkva commented 4 years ago

Addressed via f3e3770f8ce843118a2a4e28c9254c58296550a9 and 508d3b5c8f271abd0923ad8f3c8f3322ef926243