diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 38e6807cd9..d6586a35db 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -171,11 +171,7 @@ def __init__(self, paths): class NoMetricsError(DvcException): - def __init__(self): - super().__init__( - "no metric files in this repository. Use `-m/-M` options for " - "`dvc run` to mark stage outputs as metrics." - ) + pass class NoPlotsError(DvcException): diff --git a/dvc/repo/metrics/show.py b/dvc/repo/metrics/show.py index cdd787f005..33906ff3a6 100644 --- a/dvc/repo/metrics/show.py +++ b/dvc/repo/metrics/show.py @@ -36,7 +36,7 @@ def _filter(path_info): return list(filter(_filter, metrics)) -def _extract_metrics(metrics): +def _extract_metrics(metrics, path, rev): if isinstance(metrics, (int, float)): return metrics @@ -45,9 +45,18 @@ def _extract_metrics(metrics): ret = {} for key, val in metrics.items(): - m = _extract_metrics(val) + m = _extract_metrics(val, path, rev) if m: ret[key] = m + else: + logger.debug( + "Could not parse '%s' metric from '%s' at '%s' " + "due to its unsupported type: '%s'", + key, + path, + rev, + type(val).__name__, + ) return ret @@ -70,7 +79,7 @@ def _read_metrics(repo, metrics, rev): ) continue - val = _extract_metrics(val) + val = _extract_metrics(val, metric, rev) if val: res[str(metric)] = val @@ -88,6 +97,7 @@ def show( all_commits=False, ): res = {} + metrics_found = False for rev in repo.brancher( revs=revs, @@ -96,13 +106,27 @@ def show( all_commits=all_commits, ): metrics = _collect_metrics(repo, targets, recursive) + + if not metrics_found and metrics: + metrics_found = True + vals = _read_metrics(repo, metrics, rev) if vals: res[rev] = vals if not res: - raise NoMetricsError() + if metrics_found: + msg = ( + "Could not parse metric files. Use `-v` option to see more " + "details." + ) + else: + msg = ( + "no metric files in this repository. Use `-m/-M` options for " + "`dvc run` to mark stage outputs as metrics." + ) + raise NoMetricsError(msg) # Hide workspace metrics if they are the same as in the active branch try: