From dbd15a7ee8fc3ec26fd8c012ee5f1b1f491dc2d2 Mon Sep 17 00:00:00 2001 From: Sean Breckenridge Date: Tue, 7 Jun 2022 11:45:37 -0700 Subject: [PATCH] source: propogate help url for config errors --- my/core/error.py | 4 +++- my/core/source.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/my/core/error.py b/my/core/error.py index ba6368e..e6f76cd 100644 --- a/my/core/error.py +++ b/my/core/error.py @@ -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' -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, 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 click + if help_url is None: + help_url = MODULE_SETUP_URL if type(err) == ImportError: if err.name != 'my.config': return False diff --git a/my/core/source.py b/my/core/source.py index 1882dd6..6d0f0fd 100644 --- a/my/core/source.py +++ b/my/core/source.py @@ -27,6 +27,7 @@ def import_source( *, default: Iterable[T] = _DEFAULT_ITR, module_name: Optional[str] = None, + help_url: Optional[str] = None, ) -> Callable[..., Callable[..., Iterator[T]]]: """ 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 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 # it could be *any* attribute error -- we should raise this since its otherwise a fatal error # from some code in the module failing