Changeset 5327:34b988b19c6d in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/09/13 11:00:08 (7 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Add proper exception chaining, so that the user get's to see where the error happened.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/ul4c.py

    r5326 r5327  
    150150 
    151151    def __str__(self): 
    152         return "in {}".format(self.location) 
     152        if isinstance(self.location, (Template, TemplateClosure)): 
     153            if self.location.name is not None: 
     154                return "in template {!r}".format(self.location.name) 
     155            else: 
     156                return "in unnamed template" 
     157        elif isinstance(self.location, Tag): 
     158            return "in {}".format(self.location.location) 
     159        elif isinstance(self.location, AST): 
     160            return "in {}".format("".join(self.location._str(0, True))) 
     161        else: 
     162            return "in {}".format(self.location) 
    153163 
    154164 
     
    229239 
    230240### 
    231 ### Compiler stuff: Tokens and nodes for the AST 
     241### Compiler stuff: Nodes for the AST 
    232242### 
     243 
     244def handleeval(f): 
     245    def wrapped(self, keepws, vars): 
     246        try: 
     247            return (yield from f(self, keepws, vars)) 
     248        except Exception as ex: 
     249            raise Error(self) from ex 
     250    return wrapped 
     251 
    233252 
    234253class AST(Object): 
     
    415434        yield "]" 
    416435 
     436    @handleeval 
    417437    def eval(self, keepws, vars): 
    418438        result = [] 
     
    488508        yield "]" 
    489509 
     510    @handleeval 
    490511    def eval(self, keepws, vars): 
    491512        container = (yield from self.container.eval(keepws, vars)) 
     
    558579        yield "}" 
    559580 
     581    @handleeval 
    560582    def eval(self, keepws, vars): 
    561583        result = {} 
     
    637659        yield "]" 
    638660 
     661    @handleeval 
    639662    def eval(self, keepws, vars): 
    640663        container = (yield from self.container.eval(keepws, vars)) 
     
    718741        yield ")" 
    719742 
     743    @handleeval 
    720744    def eval(self, keepws, vars): 
    721745        container = (yield from self.container.eval(keepws, vars)) 
     
    760784        yield self.name 
    761785 
     786    @handleeval 
    762787    def eval(self, keepws, vars): 
    763788        yield from () 
     
    804829            yield "pass\n" 
    805830 
     831    @handleeval 
    806832    def eval(self, keepws, vars): 
    807833        for node in self.content: 
     
    855881        self.content.append(block) 
    856882 
     883    @handleeval 
    857884    def eval(self, keepws, vars): 
    858885        for node in self.content: 
     
    10301057        yield from super()._str(indent+1, keepws) 
    10311058 
     1059    @handleeval 
    10321060    def eval(self, keepws, vars): 
    10331061        container = (yield from self.container.eval(keepws, vars)) 
     
    11111139        yield self.attrname 
    11121140 
     1141    @handleeval 
    11131142    def eval(self, keepws, vars): 
    11141143        obj = (yield from self.obj.eval(keepws, vars)) 
     
    11781207        yield "]" 
    11791208 
     1209    @handleeval 
    11801210    def eval(self, keepws, vars): 
    11811211        obj = (yield from self.obj.eval(keepws, vars)) 
     
    12341264        self.obj = decoder.load() 
    12351265 
     1266    @handleeval 
    12361267    def eval(self, keepws, vars): 
    12371268        obj = (yield from self.obj.eval(keepws, vars)) 
     
    13221353        yield "\n" 
    13231354 
     1355    @handleeval 
    13241356    def eval(self, keepws, vars): 
    13251357        yield _str((yield from self.obj.eval(keepws, vars))) 
     
    13381370        yield "\n" 
    13391371 
     1372    @handleeval 
    13401373    def eval(self, keepws, vars): 
    13411374        yield _xmlescape((yield from self.obj.eval(keepws, vars))) 
     
    13541387        yield "\n" 
    13551388 
     1389    @handleeval 
    13561390    def eval(self, keepws, vars): 
    13571391        value = (yield from self.obj.eval(keepws, vars)) 
     
    13931427        self.obj2 = decoder.load() 
    13941428 
     1429    @handleeval 
    13951430    def eval(self, keepws, vars): 
    13961431        obj1 = (yield from self.obj1.eval(keepws, vars)) 
     
    17071742    @classmethod 
    17081743    def evalfold(cls, obj1, obj2): 
     1744        # This is not called from ``eval``, as it doesn't short-circuit 
    17091745        return obj1 and obj2 
    17101746 
     1747    @handleeval 
    17111748    def eval(self, keepws, vars): 
    17121749        obj1 = (yield from self.obj1.eval(keepws, vars)) 
     
    17321769    @classmethod 
    17331770    def evalfold(cls, obj1, obj2): 
     1771        # This is not called from ``eval``, as it doesn't short-circuit 
    17341772        return obj1 or obj2 
    17351773 
     1774    @handleeval 
    17361775    def eval(self, keepws, vars): 
    17371776        obj1 = (yield from self.obj1.eval(keepws, vars)) 
     
    18171856        yield "\n" 
    18181857 
     1858    @handleeval 
    18191859    def eval(self, keepws, vars): 
    18201860        value = (yield from self.value.eval(keepws, vars)) 
     
    18351875        yield "\n" 
    18361876 
     1877    @handleeval 
    18371878    def eval(self, keepws, vars): 
    18381879        value = (yield from self.value.eval(keepws, vars)) 
     
    18531894        yield "\n" 
    18541895 
     1896    @handleeval 
    18551897    def eval(self, keepws, vars): 
    18561898        value = (yield from self.value.eval(keepws, vars)) 
     
    18711913        yield "\n" 
    18721914 
     1915    @handleeval 
    18731916    def eval(self, keepws, vars): 
    18741917        value = (yield from self.value.eval(keepws, vars)) 
     
    18901933        yield "\n" 
    18911934 
     1935    @handleeval 
    18921936    def eval(self, keepws, vars): 
    18931937        value = (yield from self.value.eval(keepws, vars)) 
     
    19081952        yield "\n" 
    19091953 
     1954    @handleeval 
    19101955    def eval(self, keepws, vars): 
    19111956        value = (yield from self.value.eval(keepws, vars)) 
     
    19261971        yield "\n" 
    19271972 
     1973    @handleeval 
    19281974    def eval(self, keepws, vars): 
    19291975        value = (yield from self.value.eval(keepws, vars)) 
     
    20242070        yield ")" 
    20252071 
     2072    @handleeval 
    20262073    def eval(self, keepws, vars): 
    20272074        obj = (yield from self.obj.eval(keepws, vars)) 
     
    21242171    def _str(self, indent, keepws): 
    21252172        yield from self._formatop(self.obj) 
    2126         yield ".(" 
     2173        yield "." 
     2174        yield self.methname 
     2175        yield "(" 
    21272176        first = True 
    21282177        for arg in self.args: 
     
    21562205        yield ")" 
    21572206 
     2207    @handleeval 
    21582208    def eval(self, keepws, vars): 
    21592209        obj = (yield from self.obj.eval(keepws, vars)) 
     
    25292579            raise Error(stack[-1].location) from BlockError("block unclosed") 
    25302580 
     2581    @handleeval 
    25312582    def eval(self, keepws, vars): 
    25322583        yield from ()