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