From 4da4c69985bce24754fc43a160be1213650a77c2 Mon Sep 17 00:00:00 2001 From: Ronan Lamy Date: Fri, 23 Sep 2022 16:47:35 +0100 Subject: [PATCH] ls-url: chain exceptions and simplify exc handling --- dvc/commands/ls_url.py | 15 +++++---------- dvc/exceptions.py | 2 +- dvc/repo/ls_url.py | 4 ++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/dvc/commands/ls_url.py b/dvc/commands/ls_url.py index 05cd036b0..25e594486 100644 --- a/dvc/commands/ls_url.py +++ b/dvc/commands/ls_url.py @@ -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): diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 2168e2697..c6d4ae7f5 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -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): diff --git a/dvc/repo/ls_url.py b/dvc/repo/ls_url.py index 1088a12b3..d2248baab 100644 --- a/dvc/repo/ls_url.py +++ b/dvc/repo/ls_url.py @@ -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}]