Skip to content

Build: RepositoryError message #8999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions readthedocs/projects/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

"""Project exceptions."""

Expand Down Expand Up @@ -47,7 +46,16 @@ class RepositoryError(BuildUserError):

FAILED_TO_CHECKOUT = _('Failed to checkout revision: {}')

def get_default_message(self):
GENERIC_ERROR = _(
"There was a problem with your repository. "
"Please, take a look at the commands' output to find out the reason.",
)

@property
def CLONE_ERROR(self):
if settings.ALLOW_PRIVATE_REPOS:
return self.PRIVATE_ALLOWED
return self.PRIVATE_NOT_ALLOWED

def get_default_message(self):
return self.GENERIC_ERROR
6 changes: 4 additions & 2 deletions readthedocs/vcs_support/backends/bzr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

"""Bazaar-related utilities."""

Expand Down Expand Up @@ -36,7 +35,10 @@ def up(self):

def clone(self):
self.make_clean_working_dir()
self.run('bzr', 'checkout', self.repo_url, '.')
try:
self.run("bzr", "checkout", self.repo_url, ".")
except RepositoryError:
raise RepositoryError(RepositoryError.CLONE_ERROR)

@property
def tags(self):
Expand Down
12 changes: 7 additions & 5 deletions readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Git-related utilities."""

import structlog
import re

import git
from gitdb.util import hex_to_bin
import structlog
from django.core.exceptions import ValidationError
from git.exc import BadName, InvalidGitRepositoryError, NoSuchPathError
from gitdb.util import hex_to_bin

from readthedocs.builds.constants import EXTERNAL
from readthedocs.config import ALL
Expand All @@ -20,7 +20,6 @@
from readthedocs.projects.validators import validate_submodule_url
from readthedocs.vcs_support.base import BaseVCS, VCSVersion


log = structlog.get_logger(__name__)


Expand Down Expand Up @@ -197,8 +196,11 @@ def clone(self):

cmd.extend([self.repo_url, '.'])

code, stdout, stderr = self.run(*cmd)
return code, stdout, stderr
try:
code, stdout, stderr = self.run(*cmd)
return code, stdout, stderr
except RepositoryError:
raise RepositoryError(RepositoryError.CLONE_ERROR)

@property
def lsremote(self):
Expand Down
8 changes: 5 additions & 3 deletions readthedocs/vcs_support/backends/hg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

"""Mercurial-related utilities."""
from readthedocs.projects.exceptions import RepositoryError
Expand Down Expand Up @@ -33,8 +32,11 @@ def pull(self):

def clone(self):
self.make_clean_working_dir()
output = self.run('hg', 'clone', self.repo_url, '.')
return output
try:
output = self.run("hg", "clone", self.repo_url, ".")
return output
except RepositoryError:
raise RepositoryError(RepositoryError.CLONE_ERROR)

@property
def branches(self):
Expand Down
3 changes: 1 addition & 2 deletions readthedocs/vcs_support/backends/svn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

"""Subversion-related utilities."""

Expand Down Expand Up @@ -63,7 +62,7 @@ def co(self, identifier=None):
url = self.repo_url
retcode, out, err = self.run('svn', 'checkout', url, '.')
if retcode != 0:
raise RepositoryError
raise RepositoryError(RepositoryError.CLONE_ERROR)
return retcode, out, err

@property
Expand Down
10 changes: 6 additions & 4 deletions readthedocs/vcs_support/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Base classes for VCS backends."""
import structlog
import os
import shutil

from readthedocs.doc_builder.exceptions import BuildUserError, BuildCancelled
from readthedocs.projects.exceptions import RepositoryError
import structlog

from readthedocs.doc_builder.exceptions import BuildCancelled, BuildUserError
from readthedocs.projects.exceptions import RepositoryError

log = structlog.get_logger(__name__)

Expand Down Expand Up @@ -108,7 +108,9 @@ def run(self, *cmd, **kwargs):
raise BuildCancelled
except BuildUserError as e:
# Re raise as RepositoryError to handle it properly from outside
raise RepositoryError(str(e))
if hasattr(e, "message"):
raise RepositoryError(e.message)
raise RepositoryError

# Return a tuple to keep compatibility
return (build_cmd.exit_code, build_cmd.output, build_cmd.error)
Expand Down