core/source: use import error (#211)
core/source: use import error uses the more broad ImportError instead of ModuleNotFoundError reasoning being if some submodule (the one I'm configuring currently is my.twitter.twint) doesn't have additional imports from another parser/DAL, but it still has a config block, the user would have to create a stub-config block in their config to use the all.py file
This commit is contained in:
parent
bea2c6a201
commit
7bf316eb9a
3 changed files with 34 additions and 12 deletions
|
@ -150,6 +150,25 @@ def error_to_json(e: Exception) -> Json:
|
|||
return {'error': estr}
|
||||
|
||||
|
||||
def warn_my_config_import_error(err: ImportError) -> None:
|
||||
"""
|
||||
If the user tried to import something from my.config but it failed,
|
||||
possibly due to missing the config block in my.config?
|
||||
"""
|
||||
import re
|
||||
import click
|
||||
if err.name != 'my.config':
|
||||
return
|
||||
# parse name that user attempted to import
|
||||
em = re.match(r"cannot import name '(\w+)' from 'my.config'", str(err))
|
||||
if em is not None:
|
||||
section_name = em.group(1)
|
||||
click.echo(click.style(f"""\
|
||||
You may be missing the '{section_name}' section from your config.
|
||||
See https://github.com/karlicoss/HPI/blob/master/doc/SETUP.org#private-configuration-myconfig\
|
||||
""", fg='yellow'), err=True)
|
||||
|
||||
|
||||
def test_datetime_errors() -> None:
|
||||
import pytz
|
||||
dt_notz = datetime.now()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue