mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-26 20:03:54 -06:00
scripts/qapi/backend: Clean up create_backend()'s failure mode
create_backend()'s caller catches QAPIError, and returns non-zero exit code on catch. The caller's caller passes the exit code to sys.exit(). create_backend() doesn't care: it reports errors to stderr and sys.exit()s. Change it to raise QAPIError instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-ID: <20250311065352.992307-1-armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
parent
e95ffabbde
commit
93db9c84fc
1 changed files with 9 additions and 15 deletions
|
@ -31,34 +31,28 @@ def create_backend(path: str) -> QAPIBackend:
|
||||||
|
|
||||||
module_path, dot, class_name = path.rpartition('.')
|
module_path, dot, class_name = path.rpartition('.')
|
||||||
if not dot:
|
if not dot:
|
||||||
print("argument of -B must be of the form MODULE.CLASS",
|
raise QAPIError("argument of -B must be of the form MODULE.CLASS")
|
||||||
file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mod = import_module(module_path)
|
mod = import_module(module_path)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(f"unable to import '{module_path}': {ex}", file=sys.stderr)
|
raise QAPIError(f"unable to import '{module_path}': {ex}") from ex
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
klass = getattr(mod, class_name)
|
klass = getattr(mod, class_name)
|
||||||
except AttributeError:
|
except AttributeError as ex:
|
||||||
print(f"module '{module_path}' has no class '{class_name}'",
|
raise QAPIError(
|
||||||
file=sys.stderr)
|
f"module '{module_path}' has no class '{class_name}'") from ex
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
backend = klass()
|
backend = klass()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(f"backend '{path}' cannot be instantiated: {ex}",
|
raise QAPIError(
|
||||||
file=sys.stderr)
|
f"backend '{path}' cannot be instantiated: {ex}") from ex
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not isinstance(backend, QAPIBackend):
|
if not isinstance(backend, QAPIBackend):
|
||||||
print(f"backend '{path}' must be an instance of QAPIBackend",
|
raise QAPIError(
|
||||||
file=sys.stderr)
|
f"backend '{path}' must be an instance of QAPIBackend")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return backend
|
return backend
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue