@@ -318,7 +318,20 @@ def step_advanced_block(
318
318
result , background , scope , trace = yield from step_block_body (
319
319
state , scope , block , loc
320
320
)
321
- except PDLRuntimeError as exc :
321
+ trace = trace .model_copy (update = {"result" : result })
322
+ if block .parser is not None :
323
+ result = parse_result (block .parser , result )
324
+ if block .spec is not None and not isinstance (block , FunctionBlock ):
325
+ errors = type_check_spec (result , block .spec , block .location )
326
+ if len (errors ) > 0 :
327
+ message = "Type errors during spec checking:\n " + "\n " .join (errors )
328
+ raise PDLRuntimeError (
329
+ message ,
330
+ loc = loc ,
331
+ trace = ErrorBlock (msg = message , program = trace ),
332
+ fallback = result ,
333
+ )
334
+ except Exception as exc :
322
335
if block .fallback is None :
323
336
raise exc from exc
324
337
(
@@ -334,29 +347,19 @@ def step_advanced_block(
334
347
scope ,
335
348
loc = loc ,
336
349
)
337
- trace = trace . model_copy ( update = { "result" : result })
338
- if block . parser is not None :
339
- try :
340
- result = parse_result ( block . parser , result )
341
- except PDLRuntimeParserError as exc :
342
- raise PDLRuntimeError (
343
- exc . message ,
344
- loc = exc . loc or loc ,
345
- trace = ErrorBlock ( msg = exc . message , program = trace , fallback = result ) ,
346
- ) from exc
350
+ if block . spec is not None and not isinstance ( block , FunctionBlock ):
351
+ errors = type_check_spec ( result , block . spec , block . location )
352
+ if len ( errors ) > 0 :
353
+ message = "Type errors during spec checking: \n " + " \n " . join ( errors )
354
+ raise PDLRuntimeError ( # pylint: disable=raise-missing-from
355
+ message ,
356
+ loc = append ( loc , "fallback" ) ,
357
+ trace = ErrorBlock ( msg = message , program = trace ) ,
358
+ fallback = result ,
359
+ )
347
360
if block .assign is not None :
348
361
var = block .assign
349
362
scope = scope | {var : result }
350
- if block .spec is not None and not isinstance (block , FunctionBlock ):
351
- errors = type_check_spec (result , block .spec , block .location )
352
- if len (errors ) > 0 :
353
- message = "Type errors during spec checking:\n " + "\n " .join (errors )
354
- raise PDLRuntimeError (
355
- message ,
356
- loc = loc ,
357
- trace = ErrorBlock (msg = message , program = trace ),
358
- fallback = result ,
359
- )
360
363
if ContributeTarget .RESULT not in block .contribute :
361
364
result = ""
362
365
if ContributeTarget .CONTEXT not in block .contribute :
0 commit comments