Skip to content

Commit 1dd850a

Browse files
committed
Mark BuildEnvironmentError exceptions as Warning and do not log them
There are some exceptions risen while building documentation that are considered an ERROR from the Build perspective, but for our application are just a WARNING and shouldn't be logged as ERROR (sent to Sentry). It's not an ERROR in our application but a WARNING that the user's documentation couldn't be built.
1 parent 3593dc9 commit 1dd850a

File tree

3 files changed

+76
-34
lines changed

3 files changed

+76
-34
lines changed

readthedocs/doc_builder/environments.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from requests.exceptions import ConnectionError
2929

3030
from .exceptions import (BuildEnvironmentException, BuildEnvironmentError,
31-
BuildEnvironmentWarning, BuildEnvironmentCreationFailed)
31+
BuildEnvironmentWarning, BuildEnvironmentCreationFailed, VersionLockedError, ProjectBuildsSkippedError, YAMLParseError, BuildTimeoutError)
3232
from .constants import (DOCKER_SOCKET, DOCKER_VERSION, DOCKER_IMAGE,
3333
DOCKER_LIMITS, DOCKER_TIMEOUT_EXIT_CODE,
3434
DOCKER_OOM_EXIT_CODE, SPHINX_TEMPLATE_DIR,
@@ -40,9 +40,11 @@
4040

4141
__all__ = (
4242
'api_v2',
43-
'BuildCommand', 'DockerBuildCommand',
43+
'BuildCommand',
44+
'DockerBuildCommand',
4445
'LocalEnvironment',
45-
'LocalBuildEnvironment', 'DockerBuildEnvironment',
46+
'LocalBuildEnvironment',
47+
'DockerBuildEnvironment',
4648
)
4749

4850

@@ -409,6 +411,16 @@ class BuildEnvironment(BaseEnvironment):
409411
successful
410412
"""
411413

414+
# Exceptions considered ERROR from a Build perspective but as a WARNING for
415+
# the application itself. These exception are logged as warning and not sent
416+
# to Sentry.
417+
WARNING_EXCEPTIONS = (
418+
VersionLockedError,
419+
ProjectBuildsSkippedError,
420+
YAMLParseError,
421+
BuildTimeoutError,
422+
)
423+
412424
def __init__(self, project=None, version=None, build=None, config=None,
413425
record=True, environment=None, update_on_success=True):
414426
super(BuildEnvironment, self).__init__(project, environment)
@@ -445,21 +457,30 @@ def handle_exception(self, exc_type, exc_value, _):
445457
a failure and the context will be gracefully exited.
446458
"""
447459
if exc_type is not None:
448-
if not issubclass(exc_type, BuildEnvironmentWarning):
449-
log.error(LOG_TEMPLATE
450-
.format(project=self.project.slug,
451-
version=self.version.slug,
452-
msg=exc_value),
453-
exc_info=True,
454-
extra={
455-
'stack': True,
456-
'tags': {
457-
'build': self.build.get('id'),
458-
'project': self.project.slug,
459-
'version': self.version.slug,
460-
},
461-
})
462-
self.failure = exc_value
460+
log_level_function = None
461+
if issubclass(exc_type, BuildEnvironmentWarning):
462+
log_level_function = log.warning
463+
elif exc_type in self.WARNING_EXCEPTIONS:
464+
log_level_function = log.warning
465+
else:
466+
log_level_function = log.error
467+
468+
log_level_function(
469+
LOG_TEMPLATE.format(
470+
project=self.project.slug,
471+
version=self.version.slug,
472+
msg=exc_value,
473+
),
474+
exc_info=True,
475+
extra={
476+
'stack': True,
477+
'tags': {
478+
'build': self.build.get('id'),
479+
'project': self.project.slug,
480+
'version': self.version.slug,
481+
},
482+
})
483+
self.failure = exc_value
463484
return True
464485

465486
def record_command(self, command):

readthedocs/doc_builder/exceptions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,33 @@ class BuildEnvironmentCreationFailed(BuildEnvironmentError):
3131
)
3232

3333

34+
class VersionLockedError(BuildEnvironmentError):
35+
36+
message = ugettext_noop(
37+
'Version locked, retrying in 5 minutes.',
38+
)
39+
40+
41+
class ProjectBuildsSkippedError(BuildEnvironmentError):
42+
43+
message = ugettext_noop(
44+
'Builds for this project are temporarily disabled',
45+
)
46+
47+
48+
class YAMLParseError(BuildEnvironmentError):
49+
50+
GENERIC_WITH_PARSE_EXCEPTION = ugettext_noop(
51+
'Problem parsing YAML configuration. {exception}',
52+
)
53+
54+
55+
class BuildTimeoutError(BuildEnvironmentError):
56+
57+
message = ugettext_noop(
58+
'Build exited due to time out',
59+
)
60+
61+
3462
class BuildEnvironmentWarning(BuildEnvironmentException):
3563
pass

readthedocs/projects/tasks.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from readthedocs.doc_builder.constants import DOCKER_LIMITS
4646
from readthedocs.doc_builder.environments import (LocalBuildEnvironment,
4747
DockerBuildEnvironment)
48-
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
48+
from readthedocs.doc_builder.exceptions import BuildEnvironmentError, VersionLockedError, ProjectBuildsSkippedError, YAMLParseError, BuildTimeoutError
4949
from readthedocs.doc_builder.loader import get_builder_class
5050
from readthedocs.doc_builder.python_environments import Virtualenv, Conda
5151
from readthedocs.projects.models import APIProject
@@ -406,23 +406,19 @@ def run_setup(self, record=True):
406406
# Environment used for code checkout & initial configuration reading
407407
with self.setup_env:
408408
if self.project.skip:
409-
raise BuildEnvironmentError(
410-
_('Builds for this project are temporarily disabled'))
409+
raise ProjectBuildsSkippedError
411410
try:
412411
self.setup_vcs()
413412
except vcs_support_utils.LockTimeout as e:
414413
self.task.retry(exc=e, throw=False)
415-
raise BuildEnvironmentError(
416-
'Version locked, retrying in 5 minutes.',
417-
status_code=423
418-
)
419-
414+
raise VersionLockedError
420415
try:
421416
self.config = load_yaml_config(version=self.version)
422417
except ConfigError as e:
423-
raise BuildEnvironmentError(
424-
'Problem parsing YAML configuration. {0}'.format(str(e))
425-
)
418+
raise YAMLParseError(
419+
YAMLParseError.GENERIC_WITH_PARSE_EXCEPTION.format(
420+
exception=str(e),
421+
))
426422

427423
if self.setup_env.failure or self.config is None:
428424
self._log('Failing build because of setup failure: %s' % self.setup_env.failure)
@@ -482,12 +478,9 @@ def run_build(self, docker, record):
482478
build_id = self.build.get('id')
483479
except vcs_support_utils.LockTimeout as e:
484480
self.task.retry(exc=e, throw=False)
485-
raise BuildEnvironmentError(
486-
'Version locked, retrying in 5 minutes.',
487-
status_code=423
488-
)
481+
raise VersionLockedError
489482
except SoftTimeLimitExceeded:
490-
raise BuildEnvironmentError(_('Build exited due to time out'))
483+
raise BuildTimeoutError
491484

492485
# Finalize build and update web servers
493486
if build_id:

0 commit comments

Comments
 (0)