]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/smb: fix error handling for fundamental resource parsing
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 22 Sep 2025 17:38:24 +0000 (13:38 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 25 Sep 2025 14:58:48 +0000 (10:58 -0400)
When an smb resource is input to the smb mgr module in YAML or JSON the
fundamental parsing/deserialization is handled by resourcelib. This
module tries to be largely independent of smb mgr module and defines a
few basic exception types. When these exception types were raised the
`ceph` command line would print out a long traceback. Avoid printing
a traceback by catching these errors with a new contextmanager
(decorator) that is automatically called when using the smb ceph
mgr command api.

Fixes: https://tracker.ceph.com/issues/71992
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/cli.py

index 7efd68699811809969aee24776a27a52ff7880c0..ab92253d21ad4b33a1c904b702886da7671b31a8 100644 (file)
@@ -1,11 +1,13 @@
-from typing import Any, Callable, Tuple
+from typing import Any, Callable, Iterator, Tuple
 
+import contextlib
 import errno
 import functools
 
 import object_format
 from mgr_module import CLICommand
 
+from . import resourcelib
 from .proto import Self
 
 
@@ -53,7 +55,8 @@ class SMBCommand:
             sort_yaml=False,
         )
         rsp = object_format.Responder(_fmt)
-        self._command = cc(rsp(func))
+        ewrap = error_wrapper()
+        self._command = cc(rsp(ewrap(func)))
         return self
 
     def __get__(self, obj: Any, objtype: Any = None) -> _cmdlet:
@@ -66,3 +69,13 @@ class SMBCommand:
 class InvalidInputValue(object_format.ErrorResponseBase):
     def format_response(self) -> Tuple[int, str, str]:
         return -errno.EINVAL, "", str(self)
+
+
+@contextlib.contextmanager
+def error_wrapper() -> Iterator[None]:
+    """Context-decorator that converts between certain common exception types."""
+    try:
+        yield
+    except resourcelib.ResourceTypeError as err:
+        msg = f'failed to parse input: {err}'
+        raise InvalidInputValue(msg) from err