Skip to content

Commit a947ff2

Browse files
committed
Rename human to cargo_err
1 parent f241aa9 commit a947ff2

File tree

20 files changed

+77
-77
lines changed

20 files changed

+77
-77
lines changed

src/bin/enqueue-job.rs

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

@@ -14,7 +14,7 @@ fn main() -> AppResult<()> {
1414
.unwrap_or_else(|| String::from("db-dump.tar.gz"));
1515
tasks::dump_db(database_url, target_name).enqueue(&conn)
1616
}
17-
other => Err(human(&format!("Unrecognized job type `{}`", other))),
17+
other => Err(cargo_err(&format!("Unrecognized job type `{}`", other))),
1818
}
1919
}
2020

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, AppResult};
9+
pub use crate::util::{cargo_err, AppResult};
1010

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

src/controllers/crate_owner_invitation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn handle_invite(req: &mut dyn Request) -> AppResult<Response> {
3838
let conn = &*req.db_conn()?;
3939

4040
let crate_invite: OwnerInvitation =
41-
serde_json::from_str(&body).map_err(|_| human("invalid json request"))?;
41+
serde_json::from_str(&body).map_err(|_| cargo_err("invalid json request"))?;
4242

4343
let crate_invite = crate_invite.crate_owner_invite;
4444

src/controllers/helpers/pagination.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Page {
1818
if let Some(s) = params.get("page") {
1919
let numeric_page = s.parse()?;
2020
if numeric_page < 1 {
21-
return Err(human(&format_args!(
21+
return Err(cargo_err(&format_args!(
2222
"page indexing starts from 1, page {} is invalid",
2323
numeric_page,
2424
)));
@@ -48,7 +48,7 @@ impl PaginationOptions {
4848
.unwrap_or(Ok(DEFAULT_PER_PAGE))?;
4949

5050
if per_page > MAX_PER_PAGE {
51-
return Err(human(&format_args!(
51+
return Err(cargo_err(&format_args!(
5252
"cannot request more than {} items",
5353
MAX_PER_PAGE,
5454
)));

src/controllers/krate/owners.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ fn parse_owners_request(req: &mut dyn Request) -> AppResult<Vec<String>> {
8282
owners: Option<Vec<String>>,
8383
}
8484
let request: Request =
85-
serde_json::from_str(&body).map_err(|_| human("invalid json request"))?;
85+
serde_json::from_str(&body).map_err(|_| cargo_err("invalid json request"))?;
8686
request
8787
.owners
8888
.or(request.users)
89-
.ok_or_else(|| human("invalid json request"))
89+
.ok_or_else(|| cargo_err("invalid json request"))
9090
}
9191

9292
fn modify_owners(req: &mut dyn Request, add: bool) -> AppResult<Response> {
@@ -104,10 +104,10 @@ fn modify_owners(req: &mut dyn Request, add: bool) -> AppResult<Response> {
104104
Rights::Full => {}
105105
// Yes!
106106
Rights::Publish => {
107-
return Err(human("team members don't have permission to modify owners"));
107+
return Err(cargo_err("team members don't have permission to modify owners"));
108108
}
109109
Rights::None => {
110-
return Err(human("only owners have permission to modify owners"));
110+
return Err(cargo_err("only owners have permission to modify owners"));
111111
}
112112
}
113113

@@ -117,7 +117,7 @@ fn modify_owners(req: &mut dyn Request, add: bool) -> AppResult<Response> {
117117
let login_test =
118118
|owner: &Owner| owner.login().to_lowercase() == *login.to_lowercase();
119119
if owners.iter().any(login_test) {
120-
return Err(human(&format_args!("`{}` is already an owner", login)));
120+
return Err(cargo_err(&format_args!("`{}` is already an owner", login)));
121121
}
122122
let msg = krate.owner_add(app, &conn, user, login)?;
123123
msgs.push(msg);
@@ -128,7 +128,7 @@ fn modify_owners(req: &mut dyn Request, add: bool) -> AppResult<Response> {
128128
krate.owner_remove(app, &conn, user, login)?;
129129
}
130130
if User::owning(&krate, &conn)?.is_empty() {
131-
return Err(human(
131+
return Err(cargo_err(
132132
"cannot remove all individual owners of a crate. \
133133
Team member don't have permission to modify owners, so \
134134
at least one individual owner is required.",

src/controllers/krate/publish.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn publish(req: &mut dyn Request) -> AppResult<Response> {
4242

4343
let verified_email_address = user.verified_email(&conn)?;
4444
let verified_email_address = verified_email_address.ok_or_else(|| {
45-
human(
45+
cargo_err(
4646
"A verified email address is required to publish crates to crates.io. \
4747
Visit https://crates.io/me to set and verify your email address.",
4848
)
@@ -88,7 +88,7 @@ pub fn publish(req: &mut dyn Request) -> AppResult<Response> {
8888

8989
let owners = krate.owners(&conn)?;
9090
if user.rights(req.app(), &owners)? < Rights::Publish {
91-
return Err(human(
91+
return Err(cargo_err(
9292
"this crate exists but you don't seem to be an owner. \
9393
If you believe this is a mistake, perhaps you need \
9494
to accept an invitation to be an owner before \
@@ -97,7 +97,7 @@ pub fn publish(req: &mut dyn Request) -> AppResult<Response> {
9797
}
9898

9999
if krate.name != *name {
100-
return Err(human(&format_args!(
100+
return Err(cargo_err(&format_args!(
101101
"crate was previously named `{}`",
102102
krate.name
103103
)));
@@ -111,7 +111,7 @@ pub fn publish(req: &mut dyn Request) -> AppResult<Response> {
111111

112112
let content_length = req
113113
.content_length()
114-
.chain_error(|| human("missing header: Content-Length"))?;
114+
.chain_error(|| cargo_err("missing header: Content-Length"))?;
115115

116116
let maximums = Maximums::new(
117117
krate.max_upload_size,
@@ -120,7 +120,7 @@ pub fn publish(req: &mut dyn Request) -> AppResult<Response> {
120120
);
121121

122122
if content_length > maximums.max_upload_size {
123-
return Err(human(&format_args!(
123+
return Err(cargo_err(&format_args!(
124124
"max upload size is: {}",
125125
maximums.max_upload_size
126126
)));
@@ -221,13 +221,13 @@ fn parse_new_headers(req: &mut dyn Request) -> AppResult<(EncodableCrateUpload,
221221

222222
let max = req.app().config.max_upload_size;
223223
if metadata_length > max {
224-
return Err(human(&format_args!("max upload size is: {}", max)));
224+
return Err(cargo_err(&format_args!("max upload size is: {}", max)));
225225
}
226226
let mut json = vec![0; metadata_length as usize];
227227
read_fill(req.body(), &mut json)?;
228-
let json = String::from_utf8(json).map_err(|_| human("json body was not valid utf-8"))?;
228+
let json = String::from_utf8(json).map_err(|_| cargo_err("json body was not valid utf-8"))?;
229229
let new: EncodableCrateUpload = serde_json::from_str(&json)
230-
.map_err(|e| human(&format_args!("invalid upload request: {}", e)))?;
230+
.map_err(|e| cargo_err(&format_args!("invalid upload request: {}", e)))?;
231231

232232
// Make sure required fields are provided
233233
fn empty(s: Option<&String>) -> bool {
@@ -245,7 +245,7 @@ fn parse_new_headers(req: &mut dyn Request) -> AppResult<(EncodableCrateUpload,
245245
missing.push("authors");
246246
}
247247
if !missing.is_empty() {
248-
return Err(human(&format_args!(
248+
return Err(cargo_err(&format_args!(
249249
"missing or empty metadata fields: {}. Please \
250250
see https://doc.rust-lang.org/cargo/reference/manifest.html for \
251251
how to upload metadata",

src/controllers/user/me.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub fn update_user(req: &mut dyn Request) -> AppResult<Response> {
122122

123123
// need to check if current user matches user to be updated
124124
if &user.id.to_string() != name {
125-
return Err(human("current user does not match requested user"));
125+
return Err(cargo_err("current user does not match requested user"));
126126
}
127127

128128
#[derive(Deserialize)]
@@ -136,17 +136,17 @@ pub fn update_user(req: &mut dyn Request) -> AppResult<Response> {
136136
}
137137

138138
let user_update: UserUpdate =
139-
serde_json::from_str(&body).map_err(|_| human("invalid json request"))?;
139+
serde_json::from_str(&body).map_err(|_| cargo_err("invalid json request"))?;
140140

141141
if user_update.user.email.is_none() {
142-
return Err(human("empty email rejected"));
142+
return Err(cargo_err("empty email rejected"));
143143
}
144144

145145
let user_email = user_update.user.email.unwrap();
146146
let user_email = user_email.trim();
147147

148148
if user_email == "" {
149-
return Err(human("empty email rejected"));
149+
return Err(cargo_err("empty email rejected"));
150150
}
151151

152152
conn.transaction::<_, Box<dyn AppError>, _>(|| {
@@ -166,7 +166,7 @@ pub fn update_user(req: &mut dyn Request) -> AppResult<Response> {
166166
.set(&new_email)
167167
.returning(emails::token)
168168
.get_result::<String>(&*conn)
169-
.map_err(|_| human("Error in creating token"))?;
169+
.map_err(|_| cargo_err("Error in creating token"))?;
170170

171171
crate::email::send_user_confirm_email(user_email, &user.gh_login, &token);
172172

@@ -213,7 +213,7 @@ pub fn regenerate_token_and_send(req: &mut dyn Request) -> AppResult<Response> {
213213

214214
// need to check if current user matches user to be updated
215215
if &user.id != name {
216-
return Err(human("current user does not match requested user"));
216+
return Err(cargo_err("current user does not match requested user"));
217217
}
218218

219219
conn.transaction(|| {

src/controllers/user/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn github_access_token(req: &mut dyn Request) -> AppResult<Response> {
8585
let session_state = req.session().remove(&"github_oauth_state".to_string());
8686
let session_state = session_state.as_ref().map(|a| &a[..]);
8787
if Some(&state[..]) != session_state {
88-
return Err(human("invalid state parameter"));
88+
return Err(cargo_err("invalid state parameter"));
8989
}
9090
}
9191

@@ -96,7 +96,7 @@ pub fn github_access_token(req: &mut dyn Request) -> AppResult<Response> {
9696
.app()
9797
.github
9898
.exchange_code(code)
99-
.map_err(|s| human(&s))?;
99+
.map_err(|s| cargo_err(&s))?;
100100
let token = token.access_token();
101101
let ghuser = github::github_api::<GithubUser>(req.app(), "/user", token)?;
102102
let user = ghuser.save_to_database(&token.secret(), &*req.db_conn()?)?;

src/controllers/version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn version_and_crate(req: &mut dyn Request) -> AppResult<(Version, Crate)> {
1212
let crate_name = &req.params()["crate_id"];
1313
let semver = &req.params()["version"];
1414
if semver::Version::parse(semver).is_err() {
15-
return Err(human(&format_args!("invalid semver: {}", semver)));
15+
return Err(cargo_err(&format_args!("invalid semver: {}", semver)));
1616
};
1717
let conn = req.db_conn()?;
1818
let krate = Crate::by_name(crate_name).first::<Crate>(&*conn)?;
@@ -21,7 +21,7 @@ fn version_and_crate(req: &mut dyn Request) -> AppResult<(Version, Crate)> {
2121
.filter(versions::num.eq(semver))
2222
.first(&*conn)
2323
.map_err(|_| {
24-
human(&format_args!(
24+
cargo_err(&format_args!(
2525
"crate `{}` does not have a version `{}`",
2626
crate_name, semver
2727
))

src/controllers/version/yank.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn modify_yank(req: &mut dyn Request, yanked: bool) -> AppResult<Response> {
3333
let conn = req.db_conn()?;
3434
let owners = krate.owners(&conn)?;
3535
if user.rights(req.app(), &owners)? < Rights::Publish {
36-
return Err(human("must already be an owner to yank or unyank"));
36+
return Err(cargo_err("must already be an owner to yank or unyank"));
3737
}
3838

3939
git::yank(krate.name, version, yanked)

src/github.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::de::DeserializeOwned;
88
use std::str;
99

1010
use crate::app::App;
11-
use crate::util::{errors::NotFound, human, internal, AppError, AppResult};
11+
use crate::util::{errors::NotFound, cargo_err, internal, AppError, AppResult};
1212

1313
/// Does all the nonsense for sending a GET to Github. Doesn't handle parsing
1414
/// because custom error-code handling may be desirable. Use
@@ -35,7 +35,7 @@ fn handle_error_response(error: &reqwest::Error) -> Box<dyn AppError> {
3535
use reqwest::StatusCode as Status;
3636

3737
match error.status() {
38-
Some(Status::UNAUTHORIZED) | Some(Status::FORBIDDEN) => human(
38+
Some(Status::UNAUTHORIZED) | Some(Status::FORBIDDEN) => cargo_err(
3939
"It looks like you don't have permission \
4040
to query a necessary property from Github \
4141
to complete this request. \

src/models/dependency.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use diesel::prelude::*;
22

33
use crate::git;
4-
use crate::util::{human, AppResult};
4+
use crate::util::{cargo_err, AppResult};
55

66
use crate::models::{Crate, Version};
77
use crate::schema::*;
@@ -82,16 +82,16 @@ pub fn add_dependencies(
8282
.map(|dep| {
8383
if let Some(registry) = &dep.registry {
8484
if !registry.is_empty() {
85-
return Err(human(&format_args!("Dependency `{}` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io.", &*dep.name)));
85+
return Err(cargo_err(&format_args!("Dependency `{}` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io.", &*dep.name)));
8686
}
8787
}
8888

8989
// Match only identical names to ensure the index always references the original crate name
9090
let krate = Crate::by_exact_name(&dep.name)
9191
.first::<Crate>(&*conn)
92-
.map_err(|_| human(&format_args!("no known crate named `{}`", &*dep.name)))?;
92+
.map_err(|_| cargo_err(&format_args!("no known crate named `{}`", &*dep.name)))?;
9393
if dep.version_req == semver::VersionReq::parse("*").unwrap() {
94-
return Err(human(
94+
return Err(cargo_err(
9595
"wildcard (`*`) dependency constraints are not allowed \
9696
on crates.io. See https://doc.rust-lang.org/cargo/faq.html#can-\
9797
libraries-use--as-a-version-for-their-dependencies for more \

src/models/krate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::app::App;
1010
use crate::email;
1111
use crate::models::user;
1212
use crate::models::user::UserNoEmailType;
13-
use crate::util::{human, AppResult};
13+
use crate::util::{cargo_err, AppResult};
1414

1515
use crate::models::{
1616
Badge, Category, CrateOwner, CrateOwnerInvitation, Keyword, NewCrateOwnerInvitation, Owner,
@@ -141,15 +141,15 @@ impl<'a> NewCrate<'a> {
141141
// Manually check the string, as `Url::parse` may normalize relative URLs
142142
// making it difficult to ensure that both slashes are present.
143143
if !url.starts_with("http://") && !url.starts_with("https://") {
144-
return Err(human(&format_args!(
144+
return Err(cargo_err(&format_args!(
145145
"URL for field `{}` must begin with http:// or https:// (url: {})",
146146
field, url
147147
)));
148148
}
149149

150150
// Ensure the entire URL parses as well
151151
Url::parse(url)
152-
.map_err(|_| human(&format_args!("`{}` is not a valid url: `{}`", field, url)))?;
152+
.map_err(|_| cargo_err(&format_args!("`{}` is not a valid url: `{}`", field, url)))?;
153153
Ok(())
154154
}
155155

@@ -169,7 +169,7 @@ impl<'a> NewCrate<'a> {
169169
))
170170
.get_result::<bool>(conn)?;
171171
if reserved_name {
172-
Err(human("cannot upload a crate with a reserved name"))
172+
Err(cargo_err("cannot upload a crate with a reserved name"))
173173
} else {
174174
Ok(())
175175
}

src/models/owner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use diesel::prelude::*;
33

44
use crate::app::App;
55
use crate::github;
6-
use crate::util::{human, AppResult};
6+
use crate::util::{cargo_err, AppResult};
77

88
use crate::models::user::{UserNoEmailType, ALL_COLUMNS};
99
use crate::models::{Crate, Team, User};
@@ -77,7 +77,7 @@ impl Owner {
7777
.first::<UserNoEmailType>(conn)
7878
.map(User::from)
7979
.map(Owner::User)
80-
.map_err(|_| human(&format_args!("could not find user with login `{}`", name)))
80+
.map_err(|_| cargo_err(&format_args!("could not find user with login `{}`", name)))
8181
}
8282
}
8383

0 commit comments

Comments
 (0)