Repository: readthedocs/readthedocs.org

Issue:
BuildEnvironmentWarning logged as error
After #4804 got merged `BuildEnvironmentWarning` start being logged again as an error.

This is not a big problem but it's annoying when debugging since it uses our Sentry quota.

* https://sentry.io/read-the-docs/readthedocscom/issues/793207804/
* https://sentry.io/read-the-docs/readthedocs-org/issues/783202503/

Relating to #4590 since that could help us to avoid logging all of these.


Discussion:
@humitos 
I would like to take this issue up.
Any idea on how to start?

Edit: I'm working on it according to this [comment](https://github.com/rtfd/readthedocs.org/issues/4590#issuecomment-434682068).

Resolving patch:
diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py
--- a/readthedocs/projects/tasks.py
+++ b/readthedocs/projects/tasks.py
@@ -52,6 +52,7 @@
     BuildEnvironmentError,
     BuildEnvironmentWarning,
     BuildTimeoutError,
+    MkDocsYAMLParseError,
     ProjectBuildsSkippedError,
     VersionLockedError,
     YAMLParseError,
@@ -64,7 +65,7 @@
 from readthedocs.worker import app
 
 from .constants import LOG_TEMPLATE
-from .exceptions import RepositoryError
+from .exceptions import ProjectConfigurationError, RepositoryError
 from .models import Domain, HTMLFile, ImportedFile, Project
 from .signals import (
     after_build,
@@ -264,6 +265,10 @@ def run(self, version_pk):  # pylint: disable=arguments-differ
         return False
 
 
+# Exceptions under ``throws`` argument are considered ERROR from a Build
+# perspective (the build failed and can continue) but as a WARNING for the
+# application itself (RTD code didn't failed). These exception are logged as
+# ``INFO`` and they are not sent to Sentry.
 @app.task(
     bind=True,
     max_retries=5,
@@ -273,7 +278,11 @@ def run(self, version_pk):  # pylint: disable=arguments-differ
         ProjectBuildsSkippedError,
         YAMLParseError,
         BuildTimeoutError,
+        BuildEnvironmentWarning,
+        RepositoryError,
+        ProjectConfigurationError,
         ProjectBuildsSkippedError,
+        MkDocsYAMLParseError,
     ),
 )
 def update_docs_task(self, project_id, *args, **kwargs):
@@ -604,8 +613,6 @@ def setup_vcs(self):
         Update the checkout of the repo to make sure it's the latest.
 
         This also syncs versions in the DB.
-
-        :param build_env: Build environment
         """
         self.setup_env.update_build(state=BUILD_STATE_CLONING)
 
@@ -619,14 +626,17 @@ def setup_vcs(self):
         try:
             self.sync_repo()
         except RepositoryError:
-            # Do not log as ERROR handled exceptions
             log.warning('There was an error with the repository', exc_info=True)
+            # Re raise the exception to stop the build at this point
+            raise
         except vcs_support_utils.LockTimeout:
             log.info(
                 'Lock still active: project=%s version=%s',
                 self.project.slug,
                 self.version.slug,
             )
+            # Raise the proper exception (won't be sent to Sentry)
+            raise VersionLockedError
         except Exception:
             # Catch unhandled errors when syncing
             log.exception(
@@ -640,6 +650,8 @@ def setup_vcs(self):
                     },
                 },
             )
+            # Re raise the exception to stop the build at this point
+            raise
 
         commit = self.project.vcs_repo(self.version.slug).commit
         if commit:
@@ -1044,7 +1056,7 @@ def symlink_project(project_pk):
         sym.run()
 
 
-@app.task(queue='web', throws=(BuildEnvironmentWarning,))
+@app.task(queue='web')
 def symlink_domain(project_pk, domain, delete=False):
     """
     Symlink domain.
@@ -1093,7 +1105,7 @@ def broadcast_remove_orphan_symlinks():
     broadcast(type='web', task=remove_orphan_symlinks, args=[])
 
 
-@app.task(queue='web', throws=(BuildEnvironmentWarning,))
+@app.task(queue='web')
 def symlink_subproject(project_pk):
     project = Project.objects.get(pk=project_pk)
     for symlink in [PublicSymlink, PrivateSymlink]:


Test patch: