Skip to content

Commit b67c765

Browse files
committed
Rename Cargo{Err,Error,Result} to App*
These types represent generic application errors, and not errors specific to cargo requests/endpoints.
1 parent 307930e commit b67c765

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+223
-223
lines changed

src/background_jobs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use swirl::PerformError;
55
use crate::db::{DieselPool, DieselPooledConn};
66
use crate::git::Repository;
77
use crate::uploaders::Uploader;
8-
use crate::util::errors::{CargoErrToStdErr, CargoResult};
8+
use crate::util::errors::{AppErrToStdErr, AppResult};
99

1010
impl<'a> swirl::db::BorrowedConnection<'a> for DieselPool {
1111
type Connection = DieselPooledConn<'a>;
1212
}
1313

1414
impl swirl::db::DieselPool for DieselPool {
15-
type Error = CargoErrToStdErr;
15+
type Error = AppErrToStdErr;
1616

1717
fn get(&self) -> Result<swirl::db::DieselPooledConn<'_, Self>, Self::Error> {
18-
self.get().map_err(CargoErrToStdErr)
18+
self.get().map_err(AppErrToStdErr)
1919
}
2020
}
2121

@@ -59,10 +59,10 @@ impl Environment {
5959
pub fn connection(&self) -> Result<DieselPooledConn<'_>, PerformError> {
6060
self.connection_pool
6161
.get()
62-
.map_err(|e| CargoErrToStdErr(e).into())
62+
.map_err(|e| AppErrToStdErr(e).into())
6363
}
6464

65-
pub fn lock_index(&self) -> CargoResult<MutexGuard<'_, Repository>> {
65+
pub fn lock_index(&self) -> AppResult<MutexGuard<'_, Repository>> {
6666
let repo = self.index.lock().unwrap_or_else(PoisonError::into_inner);
6767
repo.reset_head()?;
6868
Ok(repo)

src/bin/enqueue-job.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use cargo_registry::util::{human, CargoError, CargoResult};
1+
use cargo_registry::util::{human, AppError, AppResult};
22
use cargo_registry::{db, env, tasks};
33
use diesel::PgConnection;
44

5-
fn main() -> CargoResult<()> {
5+
fn main() -> AppResult<()> {
66
let conn = db::connect_now()?;
77
let mut args = std::env::args().skip(1);
88
match &*args.next().unwrap_or_default() {
@@ -19,10 +19,10 @@ fn main() -> CargoResult<()> {
1919
}
2020

2121
/// Helper to map the `PerformError` returned by `swirl::Job::enqueue()` to a
22-
/// `CargoError`. Can be removed once `map_err()` isn't needed any more.
22+
/// `AppError`. Can be removed once `map_err()` isn't needed any more.
2323
trait Enqueue: swirl::Job {
24-
fn enqueue(self, conn: &PgConnection) -> CargoResult<()> {
25-
<Self as swirl::Job>::enqueue(self, conn).map_err(|e| CargoError::from_std_error(e))
24+
fn enqueue(self, conn: &PgConnection) -> AppResult<()> {
25+
<Self as swirl::Job>::enqueue(self, conn).map_err(|e| AppError::from_std_error(e))
2626
}
2727
}
2828

src/bin/monitor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88

99
mod on_call;
1010

11-
use cargo_registry::{db, schema::*, util::CargoResult};
11+
use cargo_registry::{db, schema::*, util::AppResult};
1212
use diesel::prelude::*;
1313

14-
fn main() -> CargoResult<()> {
14+
fn main() -> AppResult<()> {
1515
let conn = db::connect_now()?;
1616

1717
check_stalled_background_jobs(&conn)?;
1818
check_spam_attack(&conn)?;
1919
Ok(())
2020
}
2121

22-
fn check_stalled_background_jobs(conn: &PgConnection) -> CargoResult<()> {
22+
fn check_stalled_background_jobs(conn: &PgConnection) -> AppResult<()> {
2323
use cargo_registry::schema::background_jobs::dsl::*;
2424
use diesel::dsl::*;
2525

@@ -55,7 +55,7 @@ fn check_stalled_background_jobs(conn: &PgConnection) -> CargoResult<()> {
5555
Ok(())
5656
}
5757

58-
fn check_spam_attack(conn: &PgConnection) -> CargoResult<()> {
58+
fn check_spam_attack(conn: &PgConnection) -> AppResult<()> {
5959
use cargo_registry::models::krate::canon_crate_name;
6060
use diesel::dsl::*;
6161
use diesel::sql_types::Bool;
@@ -116,7 +116,7 @@ fn check_spam_attack(conn: &PgConnection) -> CargoResult<()> {
116116
Ok(())
117117
}
118118

119-
fn log_and_trigger_event(event: on_call::Event) -> CargoResult<()> {
119+
fn log_and_trigger_event(event: on_call::Event) -> AppResult<()> {
120120
match event {
121121
on_call::Event::Trigger {
122122
ref description, ..

src/bin/on_call/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_registry::util::{internal, CargoResult};
1+
use cargo_registry::util::{internal, AppResult};
22

33
use reqwest::{header, StatusCode as Status};
44

@@ -25,7 +25,7 @@ impl Event {
2525
///
2626
/// If the variant is `Trigger`, this will page whoever is on call
2727
/// (potentially waking them up at 3 AM).
28-
pub fn send(self) -> CargoResult<()> {
28+
pub fn send(self) -> AppResult<()> {
2929
let api_token = dotenv::var("PAGERDUTY_API_TOKEN")?;
3030
let service_key = dotenv::var("PAGERDUTY_INTEGRATION_KEY")?;
3131

src/boot/categories.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::{
55
db,
6-
util::errors::{internal, CargoResult, ChainError},
6+
util::errors::{internal, AppResult, ChainError},
77
};
88

99
use diesel::prelude::*;
@@ -37,7 +37,7 @@ impl Category {
3737
}
3838
}
3939

40-
fn required_string_from_toml<'a>(toml: &'a toml::value::Table, key: &str) -> CargoResult<&'a str> {
40+
fn required_string_from_toml<'a>(toml: &'a toml::value::Table, key: &str) -> AppResult<&'a str> {
4141
toml.get(key).and_then(toml::Value::as_str).chain_error(|| {
4242
internal(&format_args!(
4343
"Expected category TOML attribute '{}' to be a String",
@@ -53,7 +53,7 @@ fn optional_string_from_toml<'a>(toml: &'a toml::value::Table, key: &str) -> &'a
5353
fn categories_from_toml(
5454
categories: &toml::value::Table,
5555
parent: Option<&Category>,
56-
) -> CargoResult<Vec<Category>> {
56+
) -> AppResult<Vec<Category>> {
5757
let mut result = vec![];
5858

5959
for (slug, details) in categories {
@@ -85,12 +85,12 @@ fn categories_from_toml(
8585
Ok(result)
8686
}
8787

88-
pub fn sync(toml_str: &str) -> CargoResult<()> {
88+
pub fn sync(toml_str: &str) -> AppResult<()> {
8989
let conn = db::connect_now().unwrap();
9090
sync_with_connection(toml_str, &conn)
9191
}
9292

93-
pub fn sync_with_connection(toml_str: &str, conn: &PgConnection) -> CargoResult<()> {
93+
pub fn sync_with_connection(toml_str: &str, conn: &PgConnection) -> AppResult<()> {
9494
use crate::schema::categories::dsl::*;
9595
use diesel::dsl::all;
9696
use diesel::pg::upsert::excluded;

src/controllers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod prelude {
66
pub use conduit_router::RequestParams;
77

88
pub use crate::db::RequestTransaction;
9-
pub use crate::util::{human, CargoResult};
9+
pub use crate::util::{human, AppResult};
1010

1111
pub use crate::middleware::app::RequestApp;
1212
pub use crate::middleware::current_user::RequestUser;

src/controllers/category.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::schema::categories;
66
use crate::views::{EncodableCategory, EncodableCategoryWithSubcategories};
77

88
/// Handles the `GET /categories` route.
9-
pub fn index(req: &mut dyn Request) -> CargoResult<Response> {
9+
pub fn index(req: &mut dyn Request) -> AppResult<Response> {
1010
let conn = req.db_conn()?;
1111
let query = req.query();
1212
// FIXME: There are 69 categories, 47 top level. This isn't going to
@@ -40,7 +40,7 @@ pub fn index(req: &mut dyn Request) -> CargoResult<Response> {
4040
}
4141

4242
/// Handles the `GET /categories/:category_id` route.
43-
pub fn show(req: &mut dyn Request) -> CargoResult<Response> {
43+
pub fn show(req: &mut dyn Request) -> AppResult<Response> {
4444
let slug = &req.params()["category_id"];
4545
let conn = req.db_conn()?;
4646
let cat = Category::by_slug(slug).first::<Category>(&*conn)?;
@@ -77,7 +77,7 @@ pub fn show(req: &mut dyn Request) -> CargoResult<Response> {
7777
}
7878

7979
/// Handles the `GET /category_slugs` route.
80-
pub fn slugs(req: &mut dyn Request) -> CargoResult<Response> {
80+
pub fn slugs(req: &mut dyn Request) -> AppResult<Response> {
8181
let conn = req.db_conn()?;
8282
let slugs = categories::table
8383
.select((categories::slug, categories::slug, categories::description))

src/controllers/crate_owner_invitation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::schema::{crate_owner_invitations, crate_owners};
55
use crate::views::{EncodableCrateOwnerInvitation, InvitationResponse};
66

77
/// Handles the `GET /me/crate_owner_invitations` route.
8-
pub fn list(req: &mut dyn Request) -> CargoResult<Response> {
8+
pub fn list(req: &mut dyn Request) -> AppResult<Response> {
99
let conn = &*req.db_conn()?;
1010
let user_id = req.user()?.id;
1111

@@ -31,7 +31,7 @@ struct OwnerInvitation {
3131
}
3232

3333
/// Handles the `PUT /me/crate_owner_invitations/:crate_id` route.
34-
pub fn handle_invite(req: &mut dyn Request) -> CargoResult<Response> {
34+
pub fn handle_invite(req: &mut dyn Request) -> AppResult<Response> {
3535
let mut body = String::new();
3636
req.body().read_to_string(&mut body)?;
3737

@@ -53,7 +53,7 @@ fn accept_invite(
5353
req: &dyn Request,
5454
conn: &PgConnection,
5555
crate_invite: InvitationResponse,
56-
) -> CargoResult<Response> {
56+
) -> AppResult<Response> {
5757
use diesel::{delete, insert_into};
5858

5959
let user_id = req.user()?.id;
@@ -92,7 +92,7 @@ fn decline_invite(
9292
req: &dyn Request,
9393
conn: &PgConnection,
9494
crate_invite: InvitationResponse,
95-
) -> CargoResult<Response> {
95+
) -> AppResult<Response> {
9696
use diesel::delete;
9797

9898
let user_id = req.user()?.id;

src/controllers/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::util::{json_response, CargoResult};
1+
use crate::util::{json_response, AppResult};
22
use conduit::Response;
33

44
pub(crate) mod pagination;
55

66
pub(crate) use self::pagination::Paginate;
77

8-
pub fn ok_true() -> CargoResult<Response> {
8+
pub fn ok_true() -> AppResult<Response> {
99
#[derive(Serialize)]
1010
struct R {
1111
ok: bool,

src/controllers/helpers/pagination.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) enum Page {
1414
}
1515

1616
impl Page {
17-
fn new(params: &IndexMap<String, String>) -> CargoResult<Self> {
17+
fn new(params: &IndexMap<String, String>) -> AppResult<Self> {
1818
if let Some(s) = params.get("page") {
1919
let numeric_page = s.parse()?;
2020
if numeric_page < 1 {
@@ -38,7 +38,7 @@ pub(crate) struct PaginationOptions {
3838
}
3939

4040
impl PaginationOptions {
41-
pub(crate) fn new(params: &IndexMap<String, String>) -> CargoResult<Self> {
41+
pub(crate) fn new(params: &IndexMap<String, String>) -> AppResult<Self> {
4242
const DEFAULT_PER_PAGE: u32 = 10;
4343
const MAX_PER_PAGE: u32 = 100;
4444

@@ -70,7 +70,7 @@ impl PaginationOptions {
7070
}
7171

7272
pub(crate) trait Paginate: Sized {
73-
fn paginate(self, params: &IndexMap<String, String>) -> CargoResult<PaginatedQuery<Self>> {
73+
fn paginate(self, params: &IndexMap<String, String>) -> AppResult<PaginatedQuery<Self>> {
7474
Ok(PaginatedQuery {
7575
query: self,
7676
options: PaginationOptions::new(params)?,

src/controllers/keyword.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::models::Keyword;
55
use crate::views::EncodableKeyword;
66

77
/// Handles the `GET /keywords` route.
8-
pub fn index(req: &mut dyn Request) -> CargoResult<Response> {
8+
pub fn index(req: &mut dyn Request) -> AppResult<Response> {
99
use crate::schema::keywords;
1010

1111
let conn = req.db_conn()?;
@@ -41,7 +41,7 @@ pub fn index(req: &mut dyn Request) -> CargoResult<Response> {
4141
}
4242

4343
/// Handles the `GET /keywords/:keyword_id` route.
44-
pub fn show(req: &mut dyn Request) -> CargoResult<Response> {
44+
pub fn show(req: &mut dyn Request) -> AppResult<Response> {
4545
let name = &req.params()["keyword_id"];
4646
let conn = req.db_conn()?;
4747

src/controllers/krate/downloads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::views::EncodableVersionDownload;
1414
use crate::models::krate::to_char;
1515

1616
/// Handles the `GET /crates/:crate_id/downloads` route.
17-
pub fn downloads(req: &mut dyn Request) -> CargoResult<Response> {
17+
pub fn downloads(req: &mut dyn Request) -> AppResult<Response> {
1818
use diesel::dsl::*;
1919
use diesel::sql_types::BigInt;
2020

src/controllers/krate/follow.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::db::DieselPooledConn;
77
use crate::models::{Crate, Follow};
88
use crate::schema::*;
99

10-
fn follow_target(req: &dyn Request, conn: &DieselPooledConn<'_>) -> CargoResult<Follow> {
10+
fn follow_target(req: &dyn Request, conn: &DieselPooledConn<'_>) -> AppResult<Follow> {
1111
let user = req.user()?;
1212
let crate_name = &req.params()["crate_id"];
1313
let crate_id = Crate::by_name(crate_name)
@@ -20,7 +20,7 @@ fn follow_target(req: &dyn Request, conn: &DieselPooledConn<'_>) -> CargoResult<
2020
}
2121

2222
/// Handles the `PUT /crates/:crate_id/follow` route.
23-
pub fn follow(req: &mut dyn Request) -> CargoResult<Response> {
23+
pub fn follow(req: &mut dyn Request) -> AppResult<Response> {
2424
let conn = req.db_conn()?;
2525
let follow = follow_target(req, &conn)?;
2626
diesel::insert_into(follows::table)
@@ -32,7 +32,7 @@ pub fn follow(req: &mut dyn Request) -> CargoResult<Response> {
3232
}
3333

3434
/// Handles the `DELETE /crates/:crate_id/follow` route.
35-
pub fn unfollow(req: &mut dyn Request) -> CargoResult<Response> {
35+
pub fn unfollow(req: &mut dyn Request) -> AppResult<Response> {
3636
let conn = req.db_conn()?;
3737
let follow = follow_target(req, &conn)?;
3838
diesel::delete(&follow).execute(&*conn)?;
@@ -41,7 +41,7 @@ pub fn unfollow(req: &mut dyn Request) -> CargoResult<Response> {
4141
}
4242

4343
/// Handles the `GET /crates/:crate_id/following` route.
44-
pub fn following(req: &mut dyn Request) -> CargoResult<Response> {
44+
pub fn following(req: &mut dyn Request) -> AppResult<Response> {
4545
use diesel::dsl::exists;
4646

4747
let conn = req.db_conn()?;

src/controllers/krate/metadata.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::views::{
1717
use crate::models::krate::ALL_COLUMNS;
1818

1919
/// Handles the `GET /summary` route.
20-
pub fn summary(req: &mut dyn Request) -> CargoResult<Response> {
20+
pub fn summary(req: &mut dyn Request) -> AppResult<Response> {
2121
use crate::schema::crates::dsl::*;
2222

2323
let conn = req.db_conn()?;
@@ -26,7 +26,7 @@ pub fn summary(req: &mut dyn Request) -> CargoResult<Response> {
2626
.select(metadata::total_downloads)
2727
.get_result(&*conn)?;
2828

29-
let encode_crates = |krates: Vec<Crate>| -> CargoResult<Vec<_>> {
29+
let encode_crates = |krates: Vec<Crate>| -> AppResult<Vec<_>> {
3030
let versions = krates.versions().load::<Version>(&*conn)?;
3131
versions
3232
.grouped_by(&krates)
@@ -100,7 +100,7 @@ pub fn summary(req: &mut dyn Request) -> CargoResult<Response> {
100100
}
101101

102102
/// Handles the `GET /crates/:crate_id` route.
103-
pub fn show(req: &mut dyn Request) -> CargoResult<Response> {
103+
pub fn show(req: &mut dyn Request) -> AppResult<Response> {
104104
let name = &req.params()["crate_id"];
105105
let conn = req.db_conn()?;
106106
let krate = Crate::by_name(name).first::<Crate>(&*conn)?;
@@ -159,7 +159,7 @@ pub fn show(req: &mut dyn Request) -> CargoResult<Response> {
159159
}
160160

161161
/// Handles the `GET /crates/:crate_id/:version/readme` route.
162-
pub fn readme(req: &mut dyn Request) -> CargoResult<Response> {
162+
pub fn readme(req: &mut dyn Request) -> AppResult<Response> {
163163
let crate_name = &req.params()["crate_id"];
164164
let version = &req.params()["version"];
165165

@@ -183,7 +183,7 @@ pub fn readme(req: &mut dyn Request) -> CargoResult<Response> {
183183
/// Handles the `GET /crates/:crate_id/versions` route.
184184
// FIXME: Not sure why this is necessary since /crates/:crate_id returns
185185
// this information already, but ember is definitely requesting it
186-
pub fn versions(req: &mut dyn Request) -> CargoResult<Response> {
186+
pub fn versions(req: &mut dyn Request) -> AppResult<Response> {
187187
let crate_name = &req.params()["crate_id"];
188188
let conn = req.db_conn()?;
189189
let krate = Crate::by_name(crate_name).first::<Crate>(&*conn)?;
@@ -206,7 +206,7 @@ pub fn versions(req: &mut dyn Request) -> CargoResult<Response> {
206206
}
207207

208208
/// Handles the `GET /crates/:crate_id/reverse_dependencies` route.
209-
pub fn reverse_dependencies(req: &mut dyn Request) -> CargoResult<Response> {
209+
pub fn reverse_dependencies(req: &mut dyn Request) -> AppResult<Response> {
210210
use diesel::dsl::any;
211211

212212
let name = &req.params()["crate_id"];

0 commit comments

Comments
 (0)