[entity] rather than crashing with an IndexError on entity creation, raise a meaningful exception
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 13 Nov 2014 15:48:33 +0100
changeset 10041 504c4eacbfd8
parent 10040 2ddeece84808
child 10042 3e010722c071
[entity] rather than crashing with an IndexError on entity creation, raise a meaningful exception
entity.py
--- a/entity.py	Wed Nov 12 22:18:55 2014 +0100
+++ b/entity.py	Thu Nov 13 15:48:33 2014 +0100
@@ -519,7 +519,11 @@
             rql = 'INSERT %s X: %s' % (cls.__regid__, rql)
         else:
             rql = 'INSERT %s X' % (cls.__regid__)
-        created = execute(rql, qargs).get_entity(0, 0)
+        try:
+            created = execute(rql, qargs).get_entity(0, 0)
+        except IndexError:
+            raise Exception('could not create a %r with %r (%r)' %
+                            (cls.__regid__, rql, qargs))
         created._cw_update_attr_cache(attrcache)
         cls._cw_handle_pending_relations(created.eid, pendingrels, execute)
         return created