mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-18 07:18:26 +01:00
cli: don't inherit DvcParserError from DvcException, move to dvc.cli
This commit is contained in:
committed by
Saugat Pachhai
parent
f5baf990cf
commit
4268b5a339
+11
-4
@@ -9,6 +9,13 @@ import logging
|
||||
logger = logging.getLogger("dvc")
|
||||
|
||||
|
||||
class DvcParserError(Exception):
|
||||
"""Base class for CLI parser errors."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("parser error")
|
||||
|
||||
|
||||
def parse_args(argv=None):
|
||||
"""Parses CLI arguments.
|
||||
|
||||
@@ -16,7 +23,7 @@ def parse_args(argv=None):
|
||||
argv: optional list of arguments to parse. sys.argv is used by default.
|
||||
|
||||
Raises:
|
||||
dvc.exceptions.DvcParserError: raised for argument parsing errors.
|
||||
DvcParserError: raised for argument parsing errors.
|
||||
"""
|
||||
from .parser import get_main_parser
|
||||
|
||||
@@ -36,7 +43,7 @@ def main(argv=None): # noqa: C901
|
||||
"""
|
||||
from dvc._debug import debugtools
|
||||
from dvc.config import ConfigError
|
||||
from dvc.exceptions import DvcException, DvcParserError, NotDvcRepoError
|
||||
from dvc.exceptions import DvcException, NotDvcRepoError
|
||||
from dvc.logger import FOOTER, disable_other_loggers
|
||||
|
||||
args = None
|
||||
@@ -76,11 +83,11 @@ def main(argv=None): # noqa: C901
|
||||
except NotDvcRepoError:
|
||||
logger.exception("")
|
||||
ret = 253
|
||||
except DvcParserError:
|
||||
ret = 254
|
||||
except DvcException:
|
||||
ret = 255
|
||||
logger.exception("")
|
||||
except DvcParserError:
|
||||
ret = 254
|
||||
except Exception as exc: # noqa, pylint: disable=broad-except
|
||||
# pylint: disable=no-member
|
||||
import errno
|
||||
|
||||
+3
-3
@@ -45,6 +45,8 @@ from dvc.command import (
|
||||
version,
|
||||
)
|
||||
|
||||
from . import DvcParserError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
COMMANDS = [
|
||||
@@ -92,10 +94,8 @@ COMMANDS = [
|
||||
def _find_parser(parser, cmd_cls):
|
||||
defaults = parser._defaults # pylint: disable=protected-access
|
||||
if not cmd_cls or cmd_cls == defaults.get("func"):
|
||||
from dvc.exceptions import DvcParserError
|
||||
|
||||
parser.print_help()
|
||||
raise DvcParserError()
|
||||
raise DvcParserError
|
||||
|
||||
actions = parser._actions # pylint: disable=protected-access
|
||||
for action in actions:
|
||||
|
||||
@@ -128,13 +128,6 @@ class NotDvcRepoError(DvcException):
|
||||
"""Thrown if a directory is not a DVC repo"""
|
||||
|
||||
|
||||
class DvcParserError(DvcException):
|
||||
"""Base class for CLI parser errors."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("parser error")
|
||||
|
||||
|
||||
class CyclicGraphError(DvcException):
|
||||
def __init__(self, stages):
|
||||
assert isinstance(stages, list)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
from dvc.cli import parse_args
|
||||
from dvc.cli import DvcParserError, parse_args
|
||||
from dvc.command.add import CmdAdd
|
||||
from dvc.command.base import CmdBase
|
||||
from dvc.command.checkout import CmdCheckout
|
||||
@@ -12,7 +12,7 @@ from dvc.command.remove import CmdRemove
|
||||
from dvc.command.repro import CmdRepro
|
||||
from dvc.command.run import CmdRun
|
||||
from dvc.command.status import CmdDataStatus
|
||||
from dvc.exceptions import DvcException, DvcParserError
|
||||
from dvc.exceptions import DvcException
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from dvc.cli import parse_args
|
||||
from dvc.cli import DvcParserError, parse_args
|
||||
from dvc.command.config import CmdConfig
|
||||
from dvc.exceptions import DvcParserError
|
||||
|
||||
|
||||
def test_config_formatter():
|
||||
|
||||
@@ -4,7 +4,7 @@ from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.cli import parse_args
|
||||
from dvc.cli import DvcParserError, parse_args
|
||||
from dvc.command.experiments.apply import CmdExperimentsApply
|
||||
from dvc.command.experiments.branch import CmdExperimentsBranch
|
||||
from dvc.command.experiments.diff import CmdExperimentsDiff
|
||||
@@ -16,7 +16,7 @@ from dvc.command.experiments.push import CmdExperimentsPush
|
||||
from dvc.command.experiments.remove import CmdExperimentsRemove
|
||||
from dvc.command.experiments.run import CmdExperimentsRun
|
||||
from dvc.command.experiments.show import CmdExperimentsShow, show_experiments
|
||||
from dvc.exceptions import DvcParserError, InvalidArgumentError
|
||||
from dvc.exceptions import InvalidArgumentError
|
||||
from dvc.repo import Repo
|
||||
from dvc.stage import PipelineStage
|
||||
from tests.utils import ANY
|
||||
|
||||
Reference in New Issue
Block a user