Skip to content

Commit 20bb20f

Browse files
authored
support unrecoverable errors (#25)
1 parent 46921b1 commit 20bb20f

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.0.8
2+
3+
* **reduce usage data log level** We do not want to have so much verbosity for something that might happen a lot
4+
* **Support unrecoverable errors** Throw a 512 error for an unrecoverable error
5+
16
## 0.0.7
27

38
* **Improve code separation to help with unit tests**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.7" # pragma: no cover
1+
__version__ = "0.0.8" # pragma: no cover

unstructured_platform_plugins/etl_uvicorn/api_generator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
get_schema_dict,
2424
map_inputs,
2525
)
26+
from unstructured_platform_plugins.exceptions import UnrecoverableException
2627
from unstructured_platform_plugins.schema.json_schema import (
2728
schema_to_base_model,
2829
)
@@ -100,7 +101,7 @@ async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> Re
100101
if "usage" in inspect.signature(func).parameters:
101102
request_dict["usage"] = usage
102103
else:
103-
logger.warning("usage data not an expected parameter, omitting")
104+
logger.debug("usage data not an expected parameter, omitting")
104105
try:
105106
if inspect.isasyncgenfunction(func):
106107
# Stream response if function is an async generator
@@ -113,8 +114,15 @@ async def _stream_response():
113114

114115
return StreamingResponse(_stream_response(), media_type="application/x-ndjson")
115116
else:
116-
output = await invoke_func(func=func, kwargs=request_dict)
117-
return InvokeResponse(usage=usage, status_code=status.HTTP_200_OK, output=output)
117+
try:
118+
output = await invoke_func(func=func, kwargs=request_dict)
119+
return InvokeResponse(
120+
usage=usage, status_code=status.HTTP_200_OK, output=output
121+
)
122+
except UnrecoverableException as ex:
123+
# Thrower of this exception is responsible for logging necessary information
124+
logger.info("Unrecoverable error occurred during plugin invocation")
125+
return InvokeResponse(usage=usage, status_code=512, status_code_text=ex.message)
118126
except Exception as invoke_error:
119127
logger.error(f"failed to invoke plugin: {invoke_error}", exc_info=True)
120128
return InvokeResponse(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class UnrecoverableException(Exception):
2+
def __init__(self, message: str):
3+
super().__init__(message)
4+
self.message = message

0 commit comments

Comments
 (0)