Skip to content

Commit d901982

Browse files
authored
Merge pull request readthedocs#5118 from rtfd/humitos/logging-exceptions-rework
Logging exceptions rework
2 parents 88cffda + 1176c71 commit d901982

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

readthedocs/projects/tasks.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
BuildEnvironmentError,
5353
BuildEnvironmentWarning,
5454
BuildTimeoutError,
55+
MkDocsYAMLParseError,
5556
ProjectBuildsSkippedError,
5657
VersionLockedError,
5758
YAMLParseError,
@@ -64,7 +65,7 @@
6465
from readthedocs.worker import app
6566

6667
from .constants import LOG_TEMPLATE
67-
from .exceptions import RepositoryError
68+
from .exceptions import ProjectConfigurationError, RepositoryError
6869
from .models import Domain, HTMLFile, ImportedFile, Project
6970
from .signals import (
7071
after_build,
@@ -264,6 +265,10 @@ def run(self, version_pk): # pylint: disable=arguments-differ
264265
return False
265266

266267

268+
# Exceptions under ``throws`` argument are considered ERROR from a Build
269+
# perspective (the build failed and can continue) but as a WARNING for the
270+
# application itself (RTD code didn't failed). These exception are logged as
271+
# ``INFO`` and they are not sent to Sentry.
267272
@app.task(
268273
bind=True,
269274
max_retries=5,
@@ -273,7 +278,11 @@ def run(self, version_pk): # pylint: disable=arguments-differ
273278
ProjectBuildsSkippedError,
274279
YAMLParseError,
275280
BuildTimeoutError,
281+
BuildEnvironmentWarning,
282+
RepositoryError,
283+
ProjectConfigurationError,
276284
ProjectBuildsSkippedError,
285+
MkDocsYAMLParseError,
277286
),
278287
)
279288
def update_docs_task(self, project_id, *args, **kwargs):
@@ -604,8 +613,6 @@ def setup_vcs(self):
604613
Update the checkout of the repo to make sure it's the latest.
605614
606615
This also syncs versions in the DB.
607-
608-
:param build_env: Build environment
609616
"""
610617
self.setup_env.update_build(state=BUILD_STATE_CLONING)
611618

@@ -619,14 +626,17 @@ def setup_vcs(self):
619626
try:
620627
self.sync_repo()
621628
except RepositoryError:
622-
# Do not log as ERROR handled exceptions
623629
log.warning('There was an error with the repository', exc_info=True)
630+
# Re raise the exception to stop the build at this point
631+
raise
624632
except vcs_support_utils.LockTimeout:
625633
log.info(
626634
'Lock still active: project=%s version=%s',
627635
self.project.slug,
628636
self.version.slug,
629637
)
638+
# Raise the proper exception (won't be sent to Sentry)
639+
raise VersionLockedError
630640
except Exception:
631641
# Catch unhandled errors when syncing
632642
log.exception(
@@ -640,6 +650,8 @@ def setup_vcs(self):
640650
},
641651
},
642652
)
653+
# Re raise the exception to stop the build at this point
654+
raise
643655

644656
commit = self.project.vcs_repo(self.version.slug).commit
645657
if commit:
@@ -1044,7 +1056,7 @@ def symlink_project(project_pk):
10441056
sym.run()
10451057

10461058

1047-
@app.task(queue='web', throws=(BuildEnvironmentWarning,))
1059+
@app.task(queue='web')
10481060
def symlink_domain(project_pk, domain, delete=False):
10491061
"""
10501062
Symlink domain.
@@ -1093,7 +1105,7 @@ def broadcast_remove_orphan_symlinks():
10931105
broadcast(type='web', task=remove_orphan_symlinks, args=[])
10941106

10951107

1096-
@app.task(queue='web', throws=(BuildEnvironmentWarning,))
1108+
@app.task(queue='web')
10971109
def symlink_subproject(project_pk):
10981110
project = Project.objects.get(pk=project_pk)
10991111
for symlink in [PublicSymlink, PrivateSymlink]:

0 commit comments

Comments
 (0)