Skip to content

Commit

Permalink
exceptions: use semantic exceptions (iterative#3430)
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry authored Mar 16, 2020
1 parent 066ccea commit 1b21789
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,7 @@ def __init__(self, path_info):
format_link("https://man.dvc.org/config#cache"),
)
)


class IsADirectoryError(DvcException):
"""Raised when a file operation is requested on a directory."""
3 changes: 2 additions & 1 deletion dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dvc.config import Config
from dvc.exceptions import (
FileMissingError,
IsADirectoryError,
NotDvcRepoError,
OutputNotFoundError,
)
Expand Down Expand Up @@ -476,7 +477,7 @@ def open_by_relpath(self, path, remote=None, mode="r", encoding=None):

def _open_cached(self, out, remote=None, mode="r", encoding=None):
if out.isdir():
raise ValueError("Can't open a dir")
raise IsADirectoryError("Can't open a dir")

cache_file = self.cache.local.checksum_to_path_info(out.checksum)
cache_file = fspath_py35(cache_file)
Expand Down
6 changes: 4 additions & 2 deletions dvc/repo/reproduce.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from dvc.exceptions import ReproductionError
from dvc.exceptions import ReproductionError, InvalidArgumentError
from dvc.repo.scm_context import scm_context
from . import locked
from .graph import get_pipeline, get_pipelines
Expand Down Expand Up @@ -61,7 +61,9 @@ def reproduce(
from dvc.stage import Stage

if not target and not all_pipelines:
raise ValueError()
raise InvalidArgumentError(
"Neither target nor all_pipelines are specified."
)

interactive = kwargs.get("interactive", False)
if not interactive:
Expand Down

0 comments on commit 1b21789

Please sign in to comment.