From 9a0a47aeda7c5de37b7090c074bd9031109bb47d Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Sat, 11 Feb 2017 13:23:12 -0500 Subject: [PATCH] bt2: raise when bt2.create_plugin_from_name() finds nothing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Returning None from this function when there's no plugin is Pythonically weird: plugin = bt2.create_plugin_from_name() print(plugin.name) The execution should not reach print() here when the plugin is not found. Raise the new bt2.NoSuchPluginError exception instead. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- bindings/python/bt2/__init__.py.in | 5 ++++- bindings/python/bt2/plugin.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bindings/python/bt2/__init__.py.in b/bindings/python/bt2/__init__.py.in index 452cb3267..ba196289f 100644 --- a/bindings/python/bt2/__init__.py.in +++ b/bindings/python/bt2/__init__.py.in @@ -50,6 +50,10 @@ class FrozenError(Error): pass +class NoSuchPluginError(Error): + pass + + class UnsupportedFeature(Exception): pass @@ -66,7 +70,6 @@ class IncompleteUserClassError(Error): pass - import bt2.native_bt as _native_bt import atexit diff --git a/bindings/python/bt2/plugin.py b/bindings/python/bt2/plugin.py index 9ce4c53a6..920eb6364 100644 --- a/bindings/python/bt2/plugin.py +++ b/bindings/python/bt2/plugin.py @@ -61,7 +61,7 @@ def create_plugin_from_name(name): plugin_ptr = native_bt.plugin_create_from_name(name) if plugin_ptr is None: - return + raise bt2.NoSuchPluginError(name) return _Plugin._create_from_ptr(plugin_ptr) -- 2.34.1