ls-url: chain exceptions and simplify exc handling

This commit is contained in:
Ronan Lamy
2022-10-04 14:37:29 +03:00
committed by Ruslan Kuprieiev
parent 8a1c757497
commit 4da4c69985
3 changed files with 8 additions and 13 deletions
+5 -10
View File
@@ -3,7 +3,6 @@ import logging
from dvc.cli.command import CmdBaseNoRepo
from dvc.cli.utils import append_doc_link
from dvc.exceptions import DvcException
from dvc.ui import ui
from .ls import _prettify
@@ -15,15 +14,11 @@ class CmdListUrl(CmdBaseNoRepo):
def run(self):
from dvc.repo import Repo
try:
entries = Repo.ls_url(self.args.url, recursive=self.args.recursive)
if entries:
entries = _prettify(entries, with_color=True)
ui.write("\n".join(entries))
return 0
except DvcException:
logger.exception("failed to list '%s'", self.args.url)
return 1
entries = Repo.ls_url(self.args.url, recursive=self.args.recursive)
if entries:
entries = _prettify(entries, with_color=True)
ui.write("\n".join(entries))
return 0
def add_parser(subparsers, parent_parser):
+1 -1
View File
@@ -280,7 +280,7 @@ class PathMissingError(DvcException):
class URLMissingError(DvcException):
def __init__(self, url):
super().__init__(f"The path '{url}' does not exist.")
super().__init__(f"The path '{url}' does not exist")
class RemoteCacheRequiredError(DvcException):
+2 -2
View File
@@ -12,8 +12,8 @@ def ls_url(url, recursive=False):
fs, fs_path = parse_external_url(url)
try:
info = fs.info(fs_path)
except FileNotFoundError:
raise URLMissingError(url)
except FileNotFoundError as exc:
raise URLMissingError(url) from exc
if info["type"] != "directory":
return [{"path": info["name"], "isdir": False}]