# HG changeset patch # User Julien Jehannet # Date 1285333208 -7200 # Node ID ef47a2100c6654f6bb4d58f9689ceaf5bfe58311 # Parent 1a968e545e4eee29bb51410a9867efe43d0fc20a exception: specify expected parameter in NoSelectableException Enforce expected parameters, reformat exception message in class itself and change some log messages in calling code. diff -r 1a968e545e4e -r ef47a2100c66 _exceptions.py --- a/_exceptions.py Mon Sep 27 17:14:23 2010 +0200 +++ b/_exceptions.py Fri Sep 24 15:00:08 2010 +0200 @@ -130,14 +130,20 @@ """ class NoSelectableObject(RegistryException): - """some views with the given vid have been found but no - one is applicable to the result set - """ + """raised when no appobject is selectable for a given context.""" + def __init__(self, args, kwargs, appobjects): + self.args = args + self.kwargs = kwargs + self.appobjects = appobjects + + def __str__(self): + return ('args: %s, kwargs: %s\ncandidates: %s' + % (self.args, self.kwargs.keys(), self.appobjects)) + class UnknownProperty(RegistryException): """property found in database but unknown in registry""" - # query exception ############################################################# class QueryError(CubicWebRuntimeError): diff -r 1a968e545e4e -r ef47a2100c66 doc/book/en/devweb/controllers.rst --- a/doc/book/en/devweb/controllers.rst Mon Sep 27 17:14:23 2010 +0200 +++ b/doc/book/en/devweb/controllers.rst Fri Sep 24 15:00:08 2010 +0200 @@ -15,13 +15,12 @@ `Browsing`: -* the View controlleris associated with most browsing actions within a - CubicWeb application: it always instantiates a - :ref:`the_main_template` and lets the ResultSet/Views dispatch - system build up the whole content; it handles ObjectNotFound and - NoSelectableObject errors that may bubble up to its entry point, in - an end-user-friendly way (but other programming errors will slip - through) +* the View controller is associated with most browsing actions within a + CubicWeb application: it always instantiates a :ref:`the_main_template` and + lets the ResultSet/Views dispatch system build up the whole content; it + handles :exc:`ObjectNotFound` and :exc:`NoSelectableObject` errors that may + bubble up to its entry point, in an end-user-friendly way (but other + programming errors will slip through) * the JSon controller (same module) provides services for Ajax calls, typically using JSON as a serialization format for input, and @@ -49,7 +48,7 @@ for outgoing email notifications * the MailBugReport controller (web/views/basecontrollers.py) allows - to quickly have a `repotbug` feature in one's application + to quickly have a `reportbug` feature in one's application Registration ++++++++++++ diff -r 1a968e545e4e -r ef47a2100c66 vregistry.py --- a/vregistry.py Mon Sep 27 17:14:23 2010 +0200 +++ b/vregistry.py Fri Sep 24 15:00:08 2010 +0200 @@ -46,6 +46,7 @@ from cubicweb import RegistryNotFound, ObjectNotFound, NoSelectableObject from cubicweb.appobject import AppObject, class_regid + def _toload_info(path, extrapath, _toload=None): """return a dictionary of : and an ordered list of (file, module name) to load @@ -221,17 +222,14 @@ elif appobjectscore > 0 and appobjectscore == score: winners.append(appobject) if winners is None: - raise NoSelectableObject('args: %s\nkwargs: %s %s' - % (args, kwargs.keys(), - [repr(v) for v in appobjects])) + raise NoSelectableObject(args, kwargs, appobjects) if len(winners) > 1: # log in production environement / test, error while debugging + msg = 'select ambiguity: %s\n(args: %s, kwargs: %s)' if self.config.debugmode or self.config.mode == 'test': - raise Exception('select ambiguity, args: %s\nkwargs: %s %s' - % (args, kwargs.keys(), - [repr(v) for v in winners])) - self.error('select ambiguity, args: %s\nkwargs: %s %s', - args, kwargs.keys(), [repr(v) for v in winners]) + # raise bare exception in debug mode + raise Exception(msg % (winners, self.args, self.kwargs.keys())) + self.error(msg, winners, self.args, self.kwargs.keys()) # return the result of calling the appobject return winners[0](*args, **kwargs) diff -r 1a968e545e4e -r ef47a2100c66 web/views/basecontrollers.py --- a/web/views/basecontrollers.py Mon Sep 27 17:14:23 2010 +0200 +++ b/web/views/basecontrollers.py Fri Sep 24 15:00:08 2010 +0200 @@ -154,7 +154,6 @@ else: req.set_message(req._("You have no access to this view or it can not " "be used to display the current data.")) - self.warning("the view %s can not be applied to this query", vid) vid = req.form.get('fallbackvid') or vid_from_rset(req, rset, req.vreg.schema) view = req.vreg['views'].select(vid, req, rset=rset) return view, rset