From d789764e7cb48ab9607bf271766e8259e13fc0b2 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 22 Sep 2025 13:38:24 -0400 Subject: [PATCH] mgr/smb: fix error handling for fundamental resource parsing 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 --- src/pybind/mgr/smb/cli.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/smb/cli.py b/src/pybind/mgr/smb/cli.py index 7efd6869981..ab92253d21a 100644 --- a/src/pybind/mgr/smb/cli.py +++ b/src/pybind/mgr/smb/cli.py @@ -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 -- 2.39.5