CoastalResilienceNetwork / GeositeFramework

Mapping Framework powering TNC Coastal Resilience programs
http://maps.coastalresilience.org/network/
GNU General Public License v3.0
13 stars 10 forks source link

Migrate plugin assembly and validation #1127

Closed caseycesari closed 6 years ago

caseycesari commented 6 years ago

Overview

Migrates the C# code responsible for assembling the instance plugins, validating their contents, and setting them up for use in the instance. A lot of the code is a direct port of the C# code. Some refactoring is also done along the way.

See commit messages for details.

Connects #1090

Demo

Currently plugin data is printed to the log

INFO:root:Attempting to compile static assets...
([{u'css': [u'plugins/subregion_toggle/subregion-toggle.css']}, {u'use': {}, u'css': [u'plugins/launchpad/style.css']}, {u'use': {}, u'css': [u'sample_plugins/identify_point/main.css']}], [u'/plugins/subregion_toggle', u'/plugins/launchpad', u'/sample_plugins/identify_point'], ['tnc//plugins/subregion_toggle/main', 'tnc//plugins/launchpad/main', 'tnc//sample_plugins/identify_point/main'])
INFO:root:Finished compiling static assets.

When a plugin has malformed configuration data

INFO:root:Attempting to compile static assets...
Failed! Check that the plugin JSON config file located at /Users/ccesari/projects/GeositeFramework/src/GeositeFramework/sample_plugins/identify_point/plugin.json is properly formatted.
WARNING:root:1

When a plugin has configuration data that doesn't match the schema

INFO:root:Attempting to compile static assets...
Failed! Check that the plugin JSON config file located at /Users/ccesari/projects/GeositeFramework/src/GeositeFramework/sample_plugins/identify_point/plugin.json matches the required schema.
WARNING:root:1

When a plugin folder is missing main.js

INFO:root:Attempting to compile static assets...
Missing 'main.js' file in plugin folder: /Users/ccesari/projects/GeositeFramework/src/GeositeFramework/plugins/launchpad
WARNING:root:1

Testing Instructions

mmcfarland commented 6 years ago

Is there specific line/column information in the thrown ValueError that can be relayed to the user? Notifying of "proper formatting" may not be enough detail to let a site admin fully diagnose the issue.

caseycesari commented 6 years ago

Re: ValueError. I don't think so, but let me double-check. The python json library complains that the object it is trying to load isn't JSON. Maybe there is a JSON validation library I can try that will pinpoint the error.

fungjj92 commented 6 years ago

The raise statements (removed in cf5a65d) fed the error including line number (which is approximate, the error is arguably Line 2, col 22). Not abundantly clear what file the issue is in, if you don't have experience reading error stack traces.

screen shot 2018-10-02 at 10 13 12 am
fungjj92 commented 6 years ago

For ref, the error in region.json:

screen shot 2018-10-02 at 10 18 30 am
caseycesari commented 6 years ago

Thanks @fungjj92! I'll try and add that back in the new structure.

caseycesari commented 6 years ago

Okay. Fixed up the messages. Here's what they look like now:

INFO:root:Attempting to compile static assets...
Failed! Check that your JSON config files are properly formatted. Expecting , delimiter: line 3 column 5 (char 27)
WARNING:root:1
INFO:root:Attempting to compile static assets...
Failed! Check that your JSON config files match their schemas. 1 is not of type u'string'

Failed validating u'type' in schema[u'properties'][u'language']:
    {u'required': False, u'type': u'string'}

On instance[u'language']:
    1
WARNING:root:1
INFO:root:Attempting to compile static assets...
Failed! Check that the plugin JSON config file located at /Users/ccesari/projects/GeositeFramework/src/GeositeFramework/sample_plugins/identify_point/plugin.json is properly formatted. Expecting , delimiter: line 5 column 5 (char 74)
WARNING:root:1
INFO:root:Attempting to compile static assets...
Failed! Check that the plugin JSON config file located at /Users/ccesari/projects/GeositeFramework/src/GeositeFramework/sample_plugins/identify_point/plugin.json matches the required schema. Additional properties are not allowed (u'cssp' was unexpected)

Failed validating u'additionalProperties' in schema:
    {u'$schema': u'http://json-schema.org/draft-03/schema#',
     u'additionalProperties': False,
     u'properties': {u'css': {u'items': {u'type': u'string'},
                              u'type': u'array'},
                     u'use': {u'type': u'object'}},
     u'title': u'Geosite plugin configuration',
     u'type': u'object'}

On instance:
    {u'cssp': [u'sample_plugins/identify_point/main.css'], u'use': {}}
WARNING:root:1
mmcfarland commented 6 years ago

Cool, looks like enough that an admin could debug, perhaps with some tech help from local staff. Is it possible to decode the strings in a way that doesn't prepend the unicode literal, might cut down on the noise nicely if it's not a ton of work.

caseycesari commented 6 years ago

Good suggestion regarding the u'. Looking for a way to get rid of it.

caseycesari commented 6 years ago

Okay, pushed some more fixups. Despite repeated attempts, I couldn't get rid of the u'. I did get rid of some of the extraneous details in the error messages, while still leaving enough detail to point out the error. Here are the updated messages.

INFO:root:Attempting to compile static assets...
Failed! Check that your region.json config file is properly formatted. Expecting , delimiter: line 3 column 5 (char 27)
ERROR:root:Exiting before compiling static assets.
INFO:root:Attempting to compile static assets...
Failed! Check that your region.json config file matches the schema. 1 is not of type u'string'
ERROR:root:Exiting before compiling static assets.
INFO:root:Attempting to compile static assets...
Failed! Check that the plugin JSON config file located at /Users/ccesari/projects/GeositeFramework/src/GeositeFramework/sample_plugins/identify_point/plugin.json is properly formatted. Expecting , delimiter: line 5 column 5 (char 74)
ERROR:root:Exiting before compiling static assets.
INFO:root:Attempting to compile static assets...
Failed! Check that the plugin JSON config file located at /Users/ccesari/projects/GeositeFramework/src/GeositeFramework/sample_plugins/identify_point/plugin.json matches the required schema. Additional properties are not allowed (u'cssp' was unexpected)
ERROR:root:Exiting before compiling static assets.
caseycesari commented 6 years ago

Thanks for the reviews! Rebased and merging.