source: propogate help url for config errors

This commit is contained in:
Sean Breckenridge 2022-06-07 11:45:37 -07:00 committed by karlicoss
parent cef9b4c6d3
commit dbd15a7ee8
2 changed files with 5 additions and 2 deletions

View file

@ -155,7 +155,7 @@ def error_to_json(e: Exception) -> Json:
MODULE_SETUP_URL = 'https://github.com/karlicoss/HPI/blob/master/doc/SETUP.org#private-configuration-myconfig' MODULE_SETUP_URL = 'https://github.com/karlicoss/HPI/blob/master/doc/SETUP.org#private-configuration-myconfig'
def warn_my_config_import_error(err: Union[ImportError, AttributeError], help_url: str = MODULE_SETUP_URL) -> bool: def warn_my_config_import_error(err: Union[ImportError, AttributeError], help_url: Optional[str] = None) -> bool:
""" """
If the user tried to import something from my.config but it failed, If the user tried to import something from my.config but it failed,
possibly due to missing the config block in my.config? possibly due to missing the config block in my.config?
@ -164,6 +164,8 @@ def warn_my_config_import_error(err: Union[ImportError, AttributeError], help_ur
""" """
import re import re
import click import click
if help_url is None:
help_url = MODULE_SETUP_URL
if type(err) == ImportError: if type(err) == ImportError:
if err.name != 'my.config': if err.name != 'my.config':
return False return False

View file

@ -27,6 +27,7 @@ def import_source(
*, *,
default: Iterable[T] = _DEFAULT_ITR, default: Iterable[T] = _DEFAULT_ITR,
module_name: Optional[str] = None, module_name: Optional[str] = None,
help_url: Optional[str] = None,
) -> Callable[..., Callable[..., Iterator[T]]]: ) -> Callable[..., Callable[..., Iterator[T]]]:
""" """
doesn't really play well with types, but is used to catch doesn't really play well with types, but is used to catch
@ -64,7 +65,7 @@ class core:
""") """)
# try to check if this is a config error or based on dependencies not being installed # try to check if this is a config error or based on dependencies not being installed
if isinstance(err, (ImportError, AttributeError)): if isinstance(err, (ImportError, AttributeError)):
matched_config_err = warn_my_config_import_error(err) matched_config_err = warn_my_config_import_error(err, help_url=help_url)
# if we determined this wasn't a config error, and it was an attribute error # if we determined this wasn't a config error, and it was an attribute error
# it could be *any* attribute error -- we should raise this since its otherwise a fatal error # it could be *any* attribute error -- we should raise this since its otherwise a fatal error
# from some code in the module failing # from some code in the module failing