Skip to content

Commit

Permalink
support unrecoverable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Oct 23, 2024
1 parent 46921b1 commit ffd5fb7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.8

* **reduce usage data log level** We do not want to have so much verbosity for something that might happen a lot
* **Support unrecoverable errors** Throw a 512 error for an unrecoverable error

## 0.0.7

* **Improve code separation to help with unit tests**
Expand Down
14 changes: 11 additions & 3 deletions unstructured_platform_plugins/etl_uvicorn/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
get_schema_dict,
map_inputs,
)
from unstructured_platform_plugins.exceptions import UnrecoverableException
from unstructured_platform_plugins.schema.json_schema import (
schema_to_base_model,
)
Expand Down Expand Up @@ -100,7 +101,7 @@ async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> Re
if "usage" in inspect.signature(func).parameters:
request_dict["usage"] = usage
else:
logger.warning("usage data not an expected parameter, omitting")
logger.debug("usage data not an expected parameter, omitting")
try:
if inspect.isasyncgenfunction(func):
# Stream response if function is an async generator
Expand All @@ -113,8 +114,15 @@ async def _stream_response():

return StreamingResponse(_stream_response(), media_type="application/x-ndjson")
else:
output = await invoke_func(func=func, kwargs=request_dict)
return InvokeResponse(usage=usage, status_code=status.HTTP_200_OK, output=output)
try:
output = await invoke_func(func=func, kwargs=request_dict)
return InvokeResponse(
usage=usage, status_code=status.HTTP_200_OK, output=output
)
except UnrecoverableException as ex:
# Thrower of this exception is responsible for logging necessary information
logger.info("Unrecoverable error occurred during plugin invocation")
return InvokeResponse(usage=usage, status_code=512, status_code_text=ex.message)
except Exception as invoke_error:
logger.error(f"failed to invoke plugin: {invoke_error}", exc_info=True)
return InvokeResponse(
Expand Down
4 changes: 4 additions & 0 deletions unstructured_platform_plugins/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class UnrecoverableException(Exception):
def __init__(self, message: str):
super().__init__(message)
self.message = message

0 comments on commit ffd5fb7

Please sign in to comment.