Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/pdl/pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,8 @@ def _process_expr( # pylint: disable=too-many-return-statements
{x: scope[x] for x in free_vars if x in scope}
) # pyright: ignore
return result
except KeyboardInterrupt as exc:
raise exc from exc
except PDLRuntimeError as exc:
raise exc from exc
except TemplateSyntaxError as exc:
Expand Down Expand Up @@ -1904,6 +1906,8 @@ def get_transformed_inputs(kwargs):
update={"pdl__result": result}
) # pyright: ignore
return result, background, scope, trace
except KeyboardInterrupt as exc:
raise exc from exc
except httpx.RequestError as exc:
message = f"model '{model_id}' encountered {repr(exc)} trying to {exc.request.method} against {exc.request.url}"
raise PDLRuntimeError(
Expand Down Expand Up @@ -2129,6 +2133,8 @@ def process_call_code(
update={"code": code_s, "pdl__defsite": block.pdl__id}
),
) from exc
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
raise PDLRuntimeError(
f"Python Code error: {traceback.format_exc()}",
Expand All @@ -2151,6 +2157,8 @@ def process_call_code(
),
], # type: ignore
)
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
raise PDLRuntimeError(
f"Code error: {exc!r}",
Expand All @@ -2169,6 +2177,8 @@ def process_call_code(
}
)
)
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
raise PDLRuntimeError(
f"Shell Code error: {repr(exc)}",
Expand All @@ -2187,6 +2197,8 @@ def process_call_code(
}
)
)
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
raise PDLRuntimeError(
f"Jinja Code error: {repr(exc)}",
Expand All @@ -2205,6 +2217,8 @@ def process_call_code(
]
)
)
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
raise PDLRuntimeError(
f"PDL Code error: {repr(exc)}",
Expand Down Expand Up @@ -2233,6 +2247,8 @@ def call_python(code: str, scope: ScopeType, state: InterpreterState) -> PdlLazy
exec(c, my_namespace.__dict__) # nosec B102
# [B102:exec_used] Use of exec detected.
# This is the code that the user asked to execute. It can be executed in a docker container with the option `--sandbox`
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
message = traceback.format_exc()
raise PDLRuntimeExpressionError(message) from exc
Expand Down Expand Up @@ -2365,6 +2381,8 @@ def process_input(
try:
with open(file, encoding="utf-8") as f:
s = f.read()
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
if isinstance(exc, FileNotFoundError):
msg = f"file {str(file)} not found"
Expand Down Expand Up @@ -2649,6 +2667,8 @@ def parse_result(parser: ParserType, text: str) -> JSONReturnType:
if text == "True":
return json.loads("true")
result = json_repair.loads(text) # type: ignore[reportAssignmentType]
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
raise PDLRuntimeParserError(
f"Attempted to parse ill-formed JSON: {repr(exc)}"
Expand All @@ -2660,13 +2680,17 @@ def parse_result(parser: ParserType, text: str) -> JSONReturnType:
if line == "":
continue
result.append(json.loads(line))
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
raise PDLRuntimeParserError(
f"Attempted to parse ill-formed JSON: {repr(exc)}"
) from exc
case "yaml":
try:
result = yaml.safe_load(text)
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
raise PDLRuntimeParserError(
f"Attempted to parse ill-formed YAML: {repr(exc)}"
Expand All @@ -2686,6 +2710,8 @@ def parse_result(parser: ParserType, text: str) -> JSONReturnType:
assert False
try:
m = matcher(regex, text, flags=re.M)
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
msg = f"Fail to parse with regex {regex}: {repr(exc)}"
raise PDLRuntimeParserError(msg) from exc
Expand Down