Skip to content

dulwich: provide helpful error when auth fails #8654

@dberenbaum

Description

@dberenbaum

Related to #7670

When auth fails for dulwich operations, dvc returns a generic error:

$ dvc get https://github.com/dberenbaum/example-get-started-cp.git README.md
ERROR: failed to get 'README.md' from 'https://github.com/dberenbaum/example-get-started-cp.git' - Failed to clone repo 'https://github.com/dberenbaum/example-get-started-cp.git' to '/var/folders/24/99_tf1xj3vx8k1k_jkdmnhq00000gn/T/tmpzbwy_libdvc-clone'

There is a more helpful error returned by dulwich that specifies that no valid credentials were provided:

$ dvc get -v https://github.com/dberenbaum/example-get-started-cp.git README.md
2022-12-02 14:45:27,662 DEBUG: Creating external repo https://github.com/dberenbaum/example-get-started-cp.git@None
2022-12-02 14:45:27,662 DEBUG: erepo: git clone 'https://github.com/dberenbaum/example-get-started-cp.git' to a temporary dir
2022-12-02 14:45:27,968 DEBUG: Removing '/private/tmp/.UrQfM9Ga9PDxHUwWT3AtEQ'
2022-12-02 14:45:27,968 ERROR: failed to get 'README.md' from 'https://github.com/dberenbaum/example-get-started-cp.git' - Failed to clone repo 'https://github.com/dberenbaum/example-get-started-cp.git' to '/var/folders/24/99_tf1xj3vx8k1k_jkdmnhq00000gn/T/tmp49oa9ucwdvc-clone'
------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/scmrepo/git/backend/dulwich/__init__.py", line 200, in clone
    repo = clone_from()
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/dulwich/porcelain.py", line 538, in clone
    return client.clone(
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/dulwich/client.py", line 760, in clone
    result = self.fetch(path, target, progress=progress, depth=depth)
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/dulwich/client.py", line 837, in fetch
    result = self.fetch_pack(
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/dulwich/client.py", line 2075, in fetch_pack
    refs, server_capabilities, url = self._discover_references(
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/dulwich/client.py", line 1934, in _discover_references
    resp, read = self._http_request(url, headers)
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/dulwich/client.py", line 2215, in _http_request
    raise HTTPUnauthorized(resp.getheader("WWW-Authenticate"), url)
dulwich.client.HTTPUnauthorized: No valid credentials provided

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/dave/Code/dvc/dvc/scm.py", line 145, in clone
    git = Git.clone(url, to_path, progress=pbar.update_git, **kwargs)
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/scmrepo/git/__init__.py", line 143, in clone
    backend.clone(url, to_path, **kwargs)
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/scmrepo/git/backend/dulwich/__init__.py", line 203, in clone
    raise CloneError(url, to_path) from exc
scmrepo.exceptions.CloneError: Failed to clone repo 'https://github.com/dberenbaum/example-get-started-cp.git' to '/var/folders/24/99_tf1xj3vx8k1k_jkdmnhq00000gn/T/tmp49oa9ucwdvc-clone'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/dave/Code/dvc/dvc/commands/get.py", line 39, in _get_file_from_repo
    Repo.get(
  File "/Users/dave/Code/dvc/dvc/repo/get.py", line 50, in get
    with external_repo(
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/Users/dave/Code/dvc/dvc/external_repo.py", line 39, in external_repo
    path = _cached_clone(url, rev, for_write=for_write)
  File "/Users/dave/Code/dvc/dvc/external_repo.py", line 169, in _cached_clone
    clone_path, shallow = _clone_default_branch(url, rev, for_write=for_write)
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/funcy/decorators.py", line 45, in wrapper
    return deco(call, *dargs, **dkwargs)
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/funcy/flow.py", line 274, in wrap_with
    return call()
  File "/Users/dave/miniforge3/envs/dvc/lib/python3.10/site-packages/funcy/decorators.py", line 66, in __call__
    return self._func(*self._args, **self._kwargs)
  File "/Users/dave/Code/dvc/dvc/external_repo.py", line 239, in _clone_default_branch
    git = clone(url, clone_path)
  File "/Users/dave/Code/dvc/dvc/scm.py", line 150, in clone
    raise CloneError(str(exc))
dvc.scm.CloneError: Failed to clone repo 'https://github.com/dberenbaum/example-get-started-cp.git' to '/var/folders/24/99_tf1xj3vx8k1k_jkdmnhq00000gn/T/tmp49oa9ucwdvc-clone'
------------------------------------------------------------
2022-12-02 14:45:27,985 DEBUG: Analytics is disabled.

It would help to return that error and mention that credentials must be either provided in the url or stored somewhere that they can be retrieved by git.

Metadata

Metadata

Assignees

Labels

A: data-syncRelated to dvc get/fetch/import/pull/pushA: experimentsRelated to dvc exp

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions