Skip to content

Commit 1be3dfe

Browse files
Add InvocationError for an error without traceback. Alog cancel at info.
1 parent 278e8db commit 1be3dfe

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/labthings_fastapi/actions/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from ..dependencies.invocation import (
3434
CancelHook,
3535
InvocationCancelledError,
36+
InvocationError,
3637
invocation_logger,
3738
)
3839
from ..outputs.blob import BlobIOContextDep, blobdata_to_url_ctx
@@ -280,10 +281,16 @@ def run(self) -> None:
280281
self._status = InvocationStatus.COMPLETED
281282
self.action.emit_changed_event(self.thing, self._status)
282283
except InvocationCancelledError:
283-
logger.error(f"Invocation {self.id} was cancelled.")
284+
logger.info(f"Invocation {self.id} was cancelled.")
284285
with self._status_lock:
285286
self._status = InvocationStatus.CANCELLED
286287
self.action.emit_changed_event(self.thing, self._status)
288+
except InvocationError as e:
289+
logger.error(e)
290+
with self._status_lock:
291+
self._status = InvocationStatus.ERROR
292+
self._exception = e
293+
self.action.emit_changed_event(self.thing, self._status)
287294
except Exception as e: # skipcq: PYL-W0703
288295
logger.exception(e)
289296
with self._status_lock:

src/labthings_fastapi/dependencies/invocation.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ class InvocationCancelledError(BaseException):
117117
"""
118118

119119

120+
class InvocationError(RuntimeError):
121+
"""The invocation ended in an anticipated error state.
122+
123+
When this error is raised, action execution stops as expected. The exception will be
124+
logged at error level without a traceback, and the invocation will return with
125+
error status.
126+
127+
Unlike other types of unhandled error in a LabThings action this will not cause
128+
ASGI traceback. The ASGI traceback provides useful debug information to be logged
129+
for developers. However, for simple errors with known causes this is information
130+
overload for an average user.
131+
"""
132+
133+
120134
class CancelEvent(threading.Event):
121135
"""An Event subclass that enables cancellation of actions.
122136

src/labthings_fastapi/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""A submodule for custom LabThings-FastAPI Exceptions."""
22

3-
from .dependencies.invocation import InvocationCancelledError
3+
from .dependencies.invocation import InvocationCancelledError, InvocationError
44

55

66
class NotConnectedToServerError(RuntimeError):
@@ -13,4 +13,4 @@ class NotConnectedToServerError(RuntimeError):
1313
"""
1414

1515

16-
__all__ = ["NotConnectedToServerError", "InvocationCancelledError"]
16+
__all__ = ["NotConnectedToServerError", "InvocationCancelledError", "InvocationError"]

0 commit comments

Comments
 (0)