# -*- coding: utf-8 -*-
"""Exceptions raised when building documentation."""

from __future__ import division, print_function, unicode_literals

from django.utils.translation import ugettext_noop


class BuildEnvironmentException(Exception):

    message = None
    status_code = None

    def __init__(self, message=None, **kwargs):
        self.status_code = kwargs.pop('status_code', None) or self.status_code or 1
        message = message or self.get_default_message()
        super(BuildEnvironmentException, self).__init__(message, **kwargs)

    def get_default_message(self):
        return self.message


class BuildEnvironmentError(BuildEnvironmentException):

    GENERIC_WITH_BUILD_ID = ugettext_noop(
        'There was a problem with Read the Docs while building your documentation. '
        'Please report this to us with your build id ({build_id}).',
    )


class BuildEnvironmentCreationFailed(BuildEnvironmentError):

    message = ugettext_noop('Build environment creation failed')


class VersionLockedError(BuildEnvironmentError):

    message = ugettext_noop('Version locked, retrying in 5 minutes.')
    status_code = 423


class ProjectBuildsSkippedError(BuildEnvironmentError):

    message = ugettext_noop('Builds for this project are temporarily disabled')


class YAMLParseError(BuildEnvironmentError):

    GENERIC_WITH_PARSE_EXCEPTION = ugettext_noop(
        'Problem parsing YAML configuration. {exception}',
    )


class BuildTimeoutError(BuildEnvironmentError):

    message = ugettext_noop('Build exited due to time out')


class BuildEnvironmentWarning(BuildEnvironmentException):
    pass

readthedocs/doc_builder/exceptions.py
# -*- coding: utf-8 -*-
"""Exceptions raised when building documentation."""

from __future__ import division, print_function, unicode_literals

from django.utils.translation import ugettext_noop


class BuildEnvironmentException(Exception):

    message = None
    status_code = None

    def __init__(self, message=None, **kwargs):
        self.status_code = kwargs.pop('status_code', None) or self.status_code or 1
        message = message or self.get_default_message()
        super(BuildEnvironmentException, self).__init__(message, **kwargs)

    def get_default_message(self):
        return self.message


class BuildEnvironmentError(BuildEnvironmentException):

    GENERIC_WITH_BUILD_ID = ugettext_noop(
        'There was a problem with Read the Docs while building your documentation. '
        'Please try again later. '
        'However, if this problem persists, '
        'please report this to us with your build id ({build_id}).',
    )


class BuildEnvironmentCreationFailed(BuildEnvironmentError):

    message = ugettext_noop('Build environment creation failed')


class VersionLockedError(BuildEnvironmentError):

    message = ugettext_noop('Version locked, retrying in 5 minutes.')
    status_code = 423


class ProjectBuildsSkippedError(BuildEnvironmentError):

    message = ugettext_noop('Builds for this project are temporarily disabled')


class YAMLParseError(BuildEnvironmentError):

    GENERIC_WITH_PARSE_EXCEPTION = ugettext_noop(
        'Problem parsing YAML configuration. {exception}',
    )


class BuildTimeoutError(BuildEnvironmentError):

    message = ugettext_noop('Build exited due to time out')


class BuildEnvironmentWarning(BuildEnvironmentException):
    pass

readthedocs/doc_builder/exceptions.py
diff --git a/readthedocs/doc_builder/exceptions.py b/readthedocs/doc_builder/exceptions.py
index 360e2845256..7e303e25f78 100644
--- a/readthedocs/doc_builder/exceptions.py
+++ b/readthedocs/doc_builder/exceptions.py
@@ -24,7 +24,9 @@ class BuildEnvironmentError(BuildEnvironmentException):
 
     GENERIC_WITH_BUILD_ID = ugettext_noop(
         'There was a problem with Read the Docs while building your documentation. '
-        'Please report this to us with your build id ({build_id}).',
+        'Please try again later. '
+        'However, if this problem persists, '
+        'please report this to us with your build id ({build_id}).',
     )
 
 
diff --git a/readthedocs/rtd_tests/tests/test_doc_building.py b/readthedocs/rtd_tests/tests/test_doc_building.py
index d85e3a07038..940815cd90f 100644
--- a/readthedocs/rtd_tests/tests/test_doc_building.py
+++ b/readthedocs/rtd_tests/tests/test_doc_building.py
@@ -339,7 +339,9 @@ def test_failing_execution_with_unexpected_exception(self):
             'length': mock.ANY,
             'error': (
                 'There was a problem with Read the Docs while building your '
-                'documentation. Please report this to us with your build id (123).'
+                'documentation. Please try again later. However, if this '
+                'problem persists, please report this to us with your '
+                'build id (123).'
             ),
             'setup': '',
             'output': '',
@@ -485,9 +487,10 @@ def _inner():
             'exit_code': 1,
             'length': 0,
             'error': (
-                "There was a problem with Read the Docs while building your "
-                "documentation. Please report this to us with your build id "
-                "(123)."
+                'There was a problem with Read the Docs while building your '
+                'documentation. Please try again later. However, if this '
+                'problem persists, please report this to us with your '
+                'build id (123).'
             ),
             'setup': '',
             'output': '',

Improve unexpected error message
Many users are reporting / filling an issue in our issue tracker when this message is shown to them, which is logic because it's what the message says.

> There was a problem with Read the Docs while building your documentation. Please report this to us with your build id (1234)

Although, I think we should improve this message saying something like "if this problem persists, please report..." or something similar to that. Otherwise, sometimes it's a temporal failure and we get tons of reports.
