Skip to content

Commit 2d3e146

Browse files
humitosagjohnson
andauthored
Build: RepositoryError message (#8999)
* Build: `RepositoryError` message When a `RepositoryError` _without_ a message was raised we were setting the message as `"None"` and reporting this to the user :( This commit first checks if the exception already contains a message and use it in that case. If the exception does not contains a message, it raises it without a message so the generic one is added by the Celery handler (`on_failure`). Also, it improves the messages reported to the user to communicate a more detailed error depending the case. * Update readthedocs/projects/exceptions.py * Ignore property method upper case naming Co-authored-by: Anthony <[email protected]>
1 parent 1486de2 commit 2d3e146

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

readthedocs/projects/exceptions.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32
"""Project exceptions."""
43

@@ -47,7 +46,16 @@ class RepositoryError(BuildUserError):
4746

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

50-
def get_default_message(self):
49+
GENERIC_ERROR = _(
50+
"There was a problem cloning your repository. "
51+
"Please check the command output for more information.",
52+
)
53+
54+
@property
55+
def CLONE_ERROR(self): # noqa: N802
5156
if settings.ALLOW_PRIVATE_REPOS:
5257
return self.PRIVATE_ALLOWED
5358
return self.PRIVATE_NOT_ALLOWED
59+
60+
def get_default_message(self):
61+
return self.GENERIC_ERROR

readthedocs/vcs_support/backends/bzr.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32
"""Bazaar-related utilities."""
43

@@ -36,7 +35,10 @@ def up(self):
3635

3736
def clone(self):
3837
self.make_clean_working_dir()
39-
self.run('bzr', 'checkout', self.repo_url, '.')
38+
try:
39+
self.run("bzr", "checkout", self.repo_url, ".")
40+
except RepositoryError:
41+
raise RepositoryError(RepositoryError.CLONE_ERROR)
4042

4143
@property
4244
def tags(self):

readthedocs/vcs_support/backends/git.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Git-related utilities."""
22

3-
import structlog
43
import re
54

65
import git
7-
from gitdb.util import hex_to_bin
6+
import structlog
87
from django.core.exceptions import ValidationError
98
from git.exc import BadName, InvalidGitRepositoryError, NoSuchPathError
9+
from gitdb.util import hex_to_bin
1010

1111
from readthedocs.builds.constants import EXTERNAL
1212
from readthedocs.config import ALL
@@ -20,7 +20,6 @@
2020
from readthedocs.projects.validators import validate_submodule_url
2121
from readthedocs.vcs_support.base import BaseVCS, VCSVersion
2222

23-
2423
log = structlog.get_logger(__name__)
2524

2625

@@ -197,8 +196,11 @@ def clone(self):
197196

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

200-
code, stdout, stderr = self.run(*cmd)
201-
return code, stdout, stderr
199+
try:
200+
code, stdout, stderr = self.run(*cmd)
201+
return code, stdout, stderr
202+
except RepositoryError:
203+
raise RepositoryError(RepositoryError.CLONE_ERROR)
202204

203205
@property
204206
def lsremote(self):

readthedocs/vcs_support/backends/hg.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

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

3433
def clone(self):
3534
self.make_clean_working_dir()
36-
output = self.run('hg', 'clone', self.repo_url, '.')
37-
return output
35+
try:
36+
output = self.run("hg", "clone", self.repo_url, ".")
37+
return output
38+
except RepositoryError:
39+
raise RepositoryError(RepositoryError.CLONE_ERROR)
3840

3941
@property
4042
def branches(self):

readthedocs/vcs_support/backends/svn.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32
"""Subversion-related utilities."""
43

@@ -63,7 +62,7 @@ def co(self, identifier=None):
6362
url = self.repo_url
6463
retcode, out, err = self.run('svn', 'checkout', url, '.')
6564
if retcode != 0:
66-
raise RepositoryError
65+
raise RepositoryError(RepositoryError.CLONE_ERROR)
6766
return retcode, out, err
6867

6968
@property

readthedocs/vcs_support/base.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Base classes for VCS backends."""
2-
import structlog
32
import os
43
import shutil
54

6-
from readthedocs.doc_builder.exceptions import BuildUserError, BuildCancelled
7-
from readthedocs.projects.exceptions import RepositoryError
5+
import structlog
86

7+
from readthedocs.doc_builder.exceptions import BuildCancelled, BuildUserError
8+
from readthedocs.projects.exceptions import RepositoryError
99

1010
log = structlog.get_logger(__name__)
1111

@@ -108,7 +108,9 @@ def run(self, *cmd, **kwargs):
108108
raise BuildCancelled
109109
except BuildUserError as e:
110110
# Re raise as RepositoryError to handle it properly from outside
111-
raise RepositoryError(str(e))
111+
if hasattr(e, "message"):
112+
raise RepositoryError(e.message)
113+
raise RepositoryError
112114

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

0 commit comments

Comments
 (0)