Skip to content

Commit ca860b8

Browse files
authored
Build: better error message when rclone fails (#11796)
So, we were using incorrectly the exceptions, as we were passing a message to them, but they were expecting a message_id, I guess what we wanted is to have that error being show somewhere in the exception message, so I added a field for that, but the notification itself will show the generic error. And of course, there is now one message for rclone failures. closes #11544
1 parent 0d7643a commit ca860b8

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

readthedocs/doc_builder/environments.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ def __init__(
8080
self.user = user or settings.RTD_DOCKER_USER
8181
self._environment = environment.copy() if environment else {}
8282
if "PATH" in self._environment:
83-
raise BuildAppError("'PATH' can't be set. Use bin_path")
83+
raise BuildAppError(
84+
BuildAppError.GENERIC_WITH_BUILD_ID,
85+
exception_message="'PATH' can't be set. Use bin_path",
86+
)
8487

8588
self.build_env = build_env
8689
self.output = None
@@ -493,7 +496,10 @@ def run_command_class(
493496
if "bin_path" not in kwargs and env_path:
494497
kwargs["bin_path"] = env_path
495498
if "environment" in kwargs:
496-
raise BuildAppError("environment can't be passed in via commands.")
499+
raise BuildAppError(
500+
BuildAppError.GENERIC_WITH_BUILD_ID,
501+
exception_message="environment can't be passed in via commands.",
502+
)
497503
kwargs["environment"] = environment
498504
kwargs["build_env"] = self
499505
build_cmd = cls(cmd, **kwargs)
@@ -616,7 +622,8 @@ def __enter__(self):
616622
if state is not None:
617623
if state.get("Running") is True:
618624
raise BuildAppError(
619-
_(
625+
BuildAppError.GENERIC_WITH_BUILD_ID,
626+
exception_message=_(
620627
"A build environment is currently "
621628
"running for this version",
622629
),
@@ -629,7 +636,9 @@ def __enter__(self):
629636
client = self.get_client()
630637
client.remove_container(self.container_id)
631638
except (DockerAPIError, ConnectionError) as exc:
632-
raise BuildAppError(exc.explanation) from exc
639+
raise BuildAppError(
640+
BuildAppError.GENERIC_WITH_BUILD_ID, exception_message=exc.explanation
641+
) from exc
633642

634643
# Create the checkout path if it doesn't exist to avoid Docker creation
635644
if not os.path.exists(self.project.doc_path):
@@ -703,7 +712,9 @@ def get_client(self):
703712
)
704713
return self.client
705714
except DockerException as exc:
706-
raise BuildAppError(exc.explanation) from exc
715+
raise BuildAppError(
716+
BuildAppError.GENERIC_WITH_BUILD_ID, exception_message=exc.explanation
717+
) from exc
707718

708719
def _get_binds(self):
709720
"""
@@ -816,4 +827,6 @@ def create_container(self):
816827
)
817828
client.start(container=self.container_id)
818829
except (DockerAPIError, ConnectionError) as exc:
819-
raise BuildAppError(exc.explanation) from exc
830+
raise BuildAppError(
831+
BuildAppError.GENERIC_WITH_BUILD_ID, exception_messag=exc.explanation
832+
) from exc

readthedocs/doc_builder/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class BuildAppError(BuildBaseException):
2424
default_message = _("Build application exception")
2525

2626
GENERIC_WITH_BUILD_ID = "build:app:generic-with-build-id"
27+
UPLOAD_FAILED = "build:app:upload-failed"
2728
BUILDS_DISABLED = "build:app:project-builds-disabled"
2829
BUILD_DOCKER_UNKNOWN_ERROR = "build:app:docker:unknown-error"
2930
BUILD_TERMINATED_DUE_INACTIVITY = "build:app:terminated-due-inactivity"

readthedocs/notifications/exceptions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class NotificationBaseException(Exception):
1212

1313
default_message = _("Undefined error")
1414

15-
def __init__(self, message_id, format_values=None, **kwargs):
15+
def __init__(
16+
self, message_id, format_values=None, exception_message=None, **kwargs
17+
):
1618
self.message_id = message_id
1719
self.format_values = format_values
18-
super().__init__(self.default_message, **kwargs)
20+
super().__init__(exception_message or self.default_message, **kwargs)

readthedocs/notifications/messages.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ def get_rendered_body(self):
9696
),
9797
type=ERROR,
9898
),
99+
Message(
100+
id=BuildAppError.UPLOAD_FAILED,
101+
header=_("There was a problem while updating your documentation"),
102+
body=_(
103+
textwrap.dedent(
104+
"""
105+
Make sure this project is outputting files to the correct directory, or try again later.
106+
If this problem persists, report this error to us with your build id ({{ instance.pk }}).
107+
"""
108+
).strip(),
109+
),
110+
type=ERROR,
111+
),
99112
Message(
100113
id=BuildAppError.BUILD_TERMINATED_DUE_INACTIVITY,
101114
header=_("Build terminated due to inactivity"),

readthedocs/projects/tasks/builds.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
479479
# Known errors in our application code (e.g. we couldn't connect to
480480
# Docker API). Report a generic message to the user.
481481
if isinstance(exc, BuildAppError):
482-
message_id = BuildAppError.GENERIC_WITH_BUILD_ID
482+
message_id = exc.message_id
483483

484484
# Known errors in the user's project (e.g. invalid config file, invalid
485485
# repository, command failed, etc). Report the error back to the user
@@ -951,7 +951,10 @@ def store_build_artifacts(self):
951951
# Re-raise the exception to fail the build and handle it
952952
# automatically at `on_failure`.
953953
# It will clearly communicate the error to the user.
954-
raise BuildAppError("Error uploading files to the storage.") from exc
954+
raise BuildAppError(
955+
BuildAppError.UPLOAD_FAILED,
956+
exception_message="Error uploading files to the storage.",
957+
) from exc
955958

956959
# Delete formats
957960
for media_type in types_to_delete:
@@ -973,7 +976,10 @@ def store_build_artifacts(self):
973976
# Re-raise the exception to fail the build and handle it
974977
# automatically at `on_failure`.
975978
# It will clearly communicate the error to the user.
976-
raise BuildAppError("Error deleting files from storage.") from exc
979+
raise BuildAppError(
980+
BuildAppError.GENERIC_WITH_BUILD_ID,
981+
exception_message="Error deleting files from storage.",
982+
) from exc
977983

978984
log.info(
979985
"Store build artifacts finished.",

0 commit comments

Comments
 (0)