-
Notifications
You must be signed in to change notification settings - Fork 647
Add a concrete util::Error
type (step 3 of refactoring)
#2032
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1d0d321
Move `BadRequest` to `http`
jtgeibel bdd0114
Add `json_error` to simplify error type impls
jtgeibel 87435d0
Remove an allocation when generating error responses
jtgeibel 10e7dea
Make `AppErrToStdErr` private
jtgeibel 660a6c4
Remove usage of `std_error_no_send`
jtgeibel 616938e
Return concrete error from `db_conn`
jtgeibel 6920afe
Convert `enqueue-job` bin to a new concrete error type
jtgeibel 4d48156
Convert pagerduty bins to the concrete error type
jtgeibel 9ae544c
Convert categories boot sync to concrete error type
jtgeibel 49cc2ca
Convert email errors to `server_error`
jtgeibel b7c8c8c
Clean up error re-exports
jtgeibel 795bf15
Downgrade more return types from `AppResult` to `QueryResult`
jtgeibel 7a079a0
Simplify uploader error handling
jtgeibel 14c7d0c
Add middleware Result type
jtgeibel 08f2853
Add conversion from `s3::Error` into `util::Error`
jtgeibel 8800959
Prefer `swirl::PerformError` over `swirl::errors::PerformError`
jtgeibel 541f710
Add module level documentation describing typical usage of error types
jtgeibel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,24 @@ | ||
use cargo_registry::util::{cargo_err, AppError, AppResult}; | ||
use cargo_registry::{db, env, tasks}; | ||
use diesel::PgConnection; | ||
#![deny(clippy::all)] | ||
|
||
fn main() -> AppResult<()> { | ||
use cargo_registry::{db, env, tasks, util::Error}; | ||
use swirl::Job; | ||
|
||
fn main() -> Result<(), Error> { | ||
let conn = db::connect_now()?; | ||
let mut args = std::env::args().skip(1); | ||
|
||
let job = args.next().unwrap_or_default(); | ||
println!("Enqueueing background job: {}", job); | ||
|
||
match &*job { | ||
"update_downloads" => tasks::update_downloads().enqueue(&conn), | ||
"update_downloads" => Ok(tasks::update_downloads().enqueue(&conn)?), | ||
"dump_db" => { | ||
let database_url = args.next().unwrap_or_else(|| env("DATABASE_URL")); | ||
let target_name = args | ||
.next() | ||
.unwrap_or_else(|| String::from("db-dump.tar.gz")); | ||
tasks::dump_db(database_url, target_name).enqueue(&conn) | ||
Ok(tasks::dump_db(database_url, target_name).enqueue(&conn)?) | ||
} | ||
other => Err(cargo_err(&format!("Unrecognized job type `{}`", other))), | ||
other => Err(Error::from(format!("Unrecognized job type `{}`", other))), | ||
} | ||
} | ||
|
||
/// Helper to map the `PerformError` returned by `swirl::Job::enqueue()` to a | ||
/// `AppError`. Can be removed once `map_err()` isn't needed any more. | ||
trait Enqueue: swirl::Job { | ||
fn enqueue(self, conn: &PgConnection) -> AppResult<()> { | ||
<Self as swirl::Job>::enqueue(self, conn).map_err(|e| AppError::from_std_error(e)) | ||
} | ||
} | ||
|
||
impl<J: swirl::Job> Enqueue for J {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.