Skip to content

Commit ba4403a

Browse files
authored
Merge pull request ceph#65631 from phlogistonjohn/jjm-fix-71992
mgr/smb: fix error handling for fundamental resource parsing Reviewed-by: Adam King <[email protected]> Reviewed-by: Anoop C S <[email protected]> Reviewed-by: Avan Thakkar <[email protected]>
2 parents 4c9887d + d789764 commit ba4403a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/pybind/mgr/smb/cli.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
from typing import Any, Callable, Tuple
1+
from typing import Any, Callable, Iterator, Tuple
22

3+
import contextlib
34
import errno
45
import functools
56

67
import object_format
78
from mgr_module import CLICommand
89

10+
from . import resourcelib
911
from .proto import Self
1012

1113

@@ -53,7 +55,8 @@ def __call__(self, func: Callable) -> Self:
5355
sort_yaml=False,
5456
)
5557
rsp = object_format.Responder(_fmt)
56-
self._command = cc(rsp(func))
58+
ewrap = error_wrapper()
59+
self._command = cc(rsp(ewrap(func)))
5760
return self
5861

5962
def __get__(self, obj: Any, objtype: Any = None) -> _cmdlet:
@@ -66,3 +69,13 @@ def __get__(self, obj: Any, objtype: Any = None) -> _cmdlet:
6669
class InvalidInputValue(object_format.ErrorResponseBase):
6770
def format_response(self) -> Tuple[int, str, str]:
6871
return -errno.EINVAL, "", str(self)
72+
73+
74+
@contextlib.contextmanager
75+
def error_wrapper() -> Iterator[None]:
76+
"""Context-decorator that converts between certain common exception types."""
77+
try:
78+
yield
79+
except resourcelib.ResourceTypeError as err:
80+
msg = f'failed to parse input: {err}'
81+
raise InvalidInputValue(msg) from err

0 commit comments

Comments
 (0)