discourse/lib/tasks
Ted Johansson aaec964547
DEV: Add both safe and unsafe Discourse.store.download methods (stable) (#21499)
### Background

Several call sites use `FileStore#download` (through `Discourse.store.download`). In some cases the author seems aware that the method can raise an error if the download fails, and in some cases not. Because of this we're seeing some of these exceptions bubble all the way up and getting logged in production. Although they are not really actionable at that point. Rather each call site needs to be considered to figure out how to handle them.

### What is this change?

This change accomplishes primarily two things.

Firstly it separates the method into a safe version which will handle errors by returning `nil`, and an unsafe version which will re-package upstream errors in a new `FileStore::DownloadError` class.

Secondly it updates the call sites which have been doing error handling downstream to use the new safe version.

For backwards compatibility, there's an interim situation and a desired end state.

**Interim:**

```
FileStore#download      → Old unsafe version. Will raise any error and show a deprecation warning.
FileStore#download!     → New unsafe version. Will raise FileStore::DownloadError.
FileStore#download_safe → New safe version.   Will return nil.
```

**Desired end-state:**

```
FileStore#download  → New safe version.   Will return nil.
FileStore#download! → New unsafe version. Will raise FileStore::DownloadError.
```

### What's next?

We need to do a quick audit of the call sites that are using the old unsafe version without any error handling, as well as check for call sites in plugins other repos. Follow-up PRs incoming.
2023-05-12 11:38:08 +08:00
..
add_topic_to_quotes.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
admin.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
annotate.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
api.rake
assets.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
auto_annotate_models.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
autospec.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
avatars.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
backfill.thor
categories.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
cdn.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
db.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
destroy.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
dev.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
docker.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
emails.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
emoji.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
export.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
groups.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
i18n.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
images.rake DEV: Upgrade to Rails 7 2022-04-28 11:51:03 +02:00
import.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
incoming_emails.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
integration.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
javascript.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
log.rake
maxminddb.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
plugin.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
populate.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
populate.thor DEV: Correctly tag heredocs (#16061) 2022-02-28 20:50:55 +01:00
posts.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
profile.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
qunit.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
redis.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
release_note.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
revisions.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
rspec.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
s3.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
scheduler.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
search.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
site_settings.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
site.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
smoke_test.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
svg_icons.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
tags.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
themes.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
topics.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
turbo.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
typepad.thor
uploads.rake DEV: Add both safe and unsafe Discourse.store.download methods (stable) (#21499) 2023-05-12 11:38:08 +08:00
users.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00