Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: communicate uploading errors to users #9941

Merged
merged 6 commits into from
Jan 31, 2023

Conversation

humitos
Copy link
Member

@humitos humitos commented Jan 25, 2023

Running store_build_artifacts from inside .execute() method
instead of from .on_sucess() allow us to raise any exception and handle it
properly.

We can raise a BuildUserError to clearly communicate the specific error to the
user, or any other exception to show the generic message: "Try again or contact
us".

Besides, this allows us to fail the build instead of continuing silently
without the user noticing this:

  • there are more than 1 file of formats that don't support multiple files
  • the output path is not a directory
  • there were errors uploading the artifacts to the storage

PR based in #9940
Related to #9931

It checks for `_readthedocs/<format>` output directory to be a directory.
If it's not a directory, it silently skip that format for now.
This behavior will change once we move out `store_build_artifacts` from
`on_success` and we can communicate errors easily to the user.

Related #9931
Wrap all the logic into a class method so it's easier to follow and read.
It also remove some duplicated checks of `os.path.exists`,
making sure we are always using _validated_ paths already.
Running `store_build_artifacts` from inside `.execute()` method
instead of from `.on_sucess()` allow us to raise any exception and handle it
properly.

We can raise a `BuildUserError` to clearly communicate the specific error to the
user, or any other exception to show the generic message: "Try again or contact
us".

Besides, this allows us to *fail the build* instead of continuing silently
without the user noticing this:

- there more than 1 file of formats that don't support multiple files
- the output path is not a directory
- there were errors uploading the artifacts to the storage
@humitos humitos force-pushed the humitos/store-build-artifacts-execute branch from 2f6b59f to 00007ed Compare January 25, 2023 13:05
In case the `_readthedocs/<format>` directory is created by it contains 0 files,
we fail the build and communicate this to the user.
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a nicer implementation, and I agree that uploading is probably part of the build process. I do think we need to think a bit more about atomic uploads here, and other possible outcomes of failing builds on upload error.

readthedocs/projects/tasks/builds.py Show resolved Hide resolved
# Re-raise the exception to fail the build and handle it
# automatically at `on_failure`.
# It will clearly communicate the error to the user.
raise BuildAppError("Error uploading files to the storage.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we need more information here. Won't part of the users files already be uploaded, but not all of them? We likely need to make this atomic somehow...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think atomic uploads is the correct way. However, I'm not sure how to do that in a simple way. I suppose we could upload the content to one folder and them move it to the final one, in case the "move to the final one" action is atomic. Otherwise, we are in the same situation.

@humitos
Copy link
Member Author

humitos commented Jan 26, 2023

I like the idea of atomic uploads and I think we should go in that direction. I can create an issue to discuss it a little more in deep and decide what path to follow.

I'd like to clarify if you are OK merging this PR as-is, meaning that "if there is an error in the upload step, we fail the build and communicate this to the user --leaving half of the files updated in production" or, you prefer to come back to the previous behavior that was "if there is an error, continue the build, don't communicate to the user and leave half of the files updated in production". Basically, it's the same, but in the new one we inform the user about this.

@humitos humitos changed the base branch from humitos/storage-valid-artifacts to main January 26, 2023 10:36
# Check if there are multiple files on artifact directories.
# These output format does not support multiple files yet.
# In case multiple files are found, the upload for this format is not performed.
if artifact_type in ("htmlzip", "epub", "pdf"):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address Eric's feedback for this #9940 (comment)

@humitos
Copy link
Member Author

humitos commented Jan 26, 2023

I like the idea of atomic uploads and I think we should go in that direction. I can create an issue to discuss it a little more in deep and decide what path to follow.

I opened #9947 to track this and discuss there. I'm pinging @stsewd since he has been working with rclone and maybe knows if this is supported. I'm sure he will have some ideas there 💯

@humitos
Copy link
Member Author

humitos commented Jan 30, 2023

We are not at "atomic uploads" yet, but we will be retrying at least several times before failing the build with rclone. So, we are reducing the probabilities of failure during the upload step --and, in case of failure, we will be communicating this to the user. This implementation is better of what we currently have, so I'm happy to merge it and continue improving it in future PRs.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good once tests pass. I don't think we need to block on atomic uploads, and incremental progress is all we can hope for :)

These files are required by `store_build_artifacts` to detect there are valid
output on those folders.
@humitos humitos enabled auto-merge (squash) January 31, 2023 10:12
@humitos humitos merged commit 0c0d2c6 into main Jan 31, 2023
@humitos humitos deleted the humitos/store-build-artifacts-execute branch January 31, 2023 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants