Plugins: Make it possible to add errors to the error list.

This commit is contained in:
Neil Williams
2013-05-24 23:28:40 -07:00
parent e063743c4b
commit 3276e408b4
2 changed files with 18 additions and 0 deletions

View File

@@ -126,6 +126,18 @@ error_list = dict((
errors = Storage([(e, e) for e in error_list.keys()])
def add_error_codes(new_codes):
"""Add error codes to the error enumeration.
It is assumed that the incoming messages are marked for translation but not
yet translated, so they can be declared before pylons.i18n is ready.
"""
for code, message in new_codes.iteritems():
error_list[code] = _(message)
errors[code] = code
class RedditError(Exception):
name = None
fields = None

View File

@@ -33,6 +33,7 @@ class Plugin(object):
config = {}
live_config = {}
needs_static_build = False
errors = {}
def __init__(self, entry_point):
self.entry_point = entry_point
@@ -145,5 +146,10 @@ class PluginLoader(object):
plugin.on_load(g)
def load_controllers(self):
# this module relies on pylons.i18n._ at import time (for translating
# messages) which isn't available 'til we're in request context.
from r2.lib import errors
for plugin in self:
errors.add_error_codes(plugin.errors)
plugin.load_controllers()