This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move WarningException and some oav plans to dodal (#1423)
* Move WarningException and some oav plans to dodal * make wrapper function to raise WarningExceptions from plans * Simplify xrc tests slightly --------- Co-authored-by: Dominic Oram <[email protected]>
- Loading branch information
1 parent
35a6910
commit c5722de
Showing
10 changed files
with
88 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,46 @@ | ||
from typing import Callable, Generator, Type, TypeVar | ||
|
||
from bluesky.plan_stubs import null | ||
from bluesky.preprocessors import contingency_wrapper | ||
from bluesky.utils import Msg | ||
|
||
|
||
class WarningException(Exception): | ||
"""An exception used when we want to warn GDA of a | ||
problem but continue with UDC anyway""" | ||
|
||
pass | ||
|
||
|
||
T = TypeVar("T") | ||
|
||
|
||
def catch_exception_and_warn( | ||
exception_to_catch: Type[Exception], | ||
func: Callable[..., Generator[Msg, None, T]], | ||
*args, | ||
**kwargs, | ||
) -> Generator[Msg, None, T]: | ||
"""A plan wrapper to catch a specific exception and instead raise a WarningException, | ||
so that UDC is not halted | ||
Example usage: | ||
'def plan_which_can_raise_exception_a(*args, **kwargs): | ||
... | ||
yield from catch_exception_and_warn(ExceptionA, plan_which_can_raise_exception_a, **args, **kwargs)' | ||
This will catch ExceptionA raised by the plan and instead raise a WarningException | ||
""" | ||
|
||
def warn_if_exception_matches(exception: Exception): | ||
if isinstance(exception, exception_to_catch): | ||
raise WarningException(str(exception)) | ||
yield from null() | ||
|
||
return ( | ||
yield from contingency_wrapper( | ||
func(*args, **kwargs), | ||
except_plan=warn_if_exception_matches, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.