Catch ConfigError in register()
This commit is contained in:
parent
a5b57601da
commit
d9e3dec0c2
@ -2,6 +2,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from i3pystatus.core.exceptions import ConfigError
|
||||||
|
|
||||||
from i3pystatus.core.imputil import ClassFinder
|
from i3pystatus.core.imputil import ClassFinder
|
||||||
from i3pystatus.core import io, util
|
from i3pystatus.core import io, util
|
||||||
@ -54,6 +55,7 @@ class Status:
|
|||||||
|
|
||||||
def register(self, module, *args, **kwargs):
|
def register(self, module, *args, **kwargs):
|
||||||
"""Register a new module."""
|
"""Register a new module."""
|
||||||
|
from i3pystatus.text import Text
|
||||||
|
|
||||||
if module:
|
if module:
|
||||||
try:
|
try:
|
||||||
@ -61,7 +63,6 @@ class Status:
|
|||||||
except ImportError as import_error:
|
except ImportError as import_error:
|
||||||
if import_error.name and not import_error.path and isinstance(module, str):
|
if import_error.name and not import_error.path and isinstance(module, str):
|
||||||
# This is a package/module not found exception raised by importing a module on-the-fly
|
# This is a package/module not found exception raised by importing a module on-the-fly
|
||||||
from i3pystatus.text import Text
|
|
||||||
return self.modules.append(Text(
|
return self.modules.append(Text(
|
||||||
color="#FF0000",
|
color="#FF0000",
|
||||||
text="{i3py_mod}: Missing Python module '{missing_module}'".format(
|
text="{i3py_mod}: Missing Python module '{missing_module}'".format(
|
||||||
@ -69,6 +70,10 @@ class Status:
|
|||||||
missing_module=import_error.name)))
|
missing_module=import_error.name)))
|
||||||
else:
|
else:
|
||||||
raise import_error
|
raise import_error
|
||||||
|
except ConfigError as configuration_error:
|
||||||
|
return self.modules.append(Text(
|
||||||
|
color="#FF0000",
|
||||||
|
text=configuration_error.message))
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@ class ConfigError(Exception):
|
|||||||
"""ABC for configuration exceptions"""
|
"""ABC for configuration exceptions"""
|
||||||
|
|
||||||
def __init__(self, module, *args, **kwargs):
|
def __init__(self, module, *args, **kwargs):
|
||||||
message = "Module '{0}': {1}".format(
|
self.message = "Module '{0}': {1}".format(
|
||||||
module, self.format(*args, **kwargs))
|
module, self.format(*args, **kwargs))
|
||||||
|
|
||||||
super().__init__(message)
|
super().__init__(self.message)
|
||||||
|
|
||||||
def format(self, *args, **kwargs):
|
def format(self, *args, **kwargs):
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
Reference in New Issue
Block a user