mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
ls-url: chain exceptions and simplify exc handling
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
8a1c757497
commit
4da4c69985
@@ -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
|
||||
|
||||
|
||||
def add_parser(subparsers, parent_parser):
|
||||
|
||||
+1
-1
@@ -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
@@ -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}]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user