# Buggy code
def show_metrics(metrics, all_branches=False, all_tags=False, all_commits=False):
    from flatten_json import flatten

    from dvc.utils.diff import format_dict

    # When `metrics` contains a `None` key, it means that some files
    # specified as `targets` in `repo.metrics.show` didn't contain any metrics.
    missing = metrics.pop(None, None)

    for branch, val in metrics.items():
        if all_branches or all_tags or all_commits:
            logger.info(f"{branch}:")

        for fname, metric in val.items():
            if not isinstance(metric, dict):
                logger.info("\t{}: {}".format(fname, str(metric)))
                continue

            logger.info(f"\t{fname}:")
            for key, value in flatten(format_dict(metric), ".").items():
                logger.info(f"\t\t{key}: {value}")

    if missing:
        raise BadMetricError(missing)


# Traceback (ImportError)
2020-08-30 08:57:43,226 DEBUG: fetched: [(3,)]
2020-08-30 08:57:43,228 DEBUG: fetched: [(21770,)]
2020-08-30 08:57:43,246 ERROR: unexpected error - cannot import name 'check_if_numbers_are_consecutive'
------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/dvc/main.py", line 75, in main
ret = cmd.run()
File "/usr/local/lib/python3.6/dist-packages/dvc/command/repro.py", line 47, in run
params=self.args.params,
File "/usr/local/lib/python3.6/dist-packages/dvc/repo/__init__.py", line 34, in wrapper
ret = f(repo, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/dvc/repo/scm_context.py", line 4, in run
result = method(repo, *args, **kw)
File "/usr/local/lib/python3.6/dist-packages/dvc/repo/reproduce.py", line 74, in reproduce
params = _parse_params(kwargs.pop("params", []))
File "/usr/local/lib/python3.6/dist-packages/dvc/repo/reproduce.py", line 122, in _parse_params
from flatten_json import unflatten
File "/usr/local/lib/python3.6/dist-packages/flatten_json.py", line 13, in <module>
from util import check_if_numbers_are_consecutive
ImportError: cannot import name 'check_if_numbers_are_consecutive'
------------------------------------------------------------
Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!
2020-08-30 08:57:43,249 DEBUG: Analytics is enabled.
2020-08-30 08:57:43,279 DEBUG: Trying to spawn '['daemon', '-q', 'analytics', '/tmp/tmpkskduifx']'
2020-08-30 08:57:43,280 DEBUG: Spawned '['daemon', '-q', 'analytics', '/tmp/tmpkskduifx']'

# Fixed code
def show_metrics(metrics, all_branches=False, all_tags=False, all_commits=False):
    from dvc.utils.diff import format_dict
    from dvc.utils.flatten import flatten

    # When `metrics` contains a `None` key, it means that some files
    # specified as `targets` in `repo.metrics.show` didn't contain any metrics.
    missing = metrics.pop(None, None)

    for branch, val in metrics.items():
        if all_branches or all_tags or all_commits:
            logger.info(f"{branch}:")

        for fname, metric in val.items():
            if not isinstance(metric, dict):
                logger.info("\t{}: {}".format(fname, str(metric)))
                continue

            logger.info(f"\t{fname}:")
            for key, value in flatten(format_dict(metric)).items():
                logger.info(f"\t\t{key}: {value}")

    if missing:
        raise BadMetricError(missing)