Skip to content

Commit eb13148

Browse files
Improve error names
1 parent 951a29f commit eb13148

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

.idea/codeStyles/codeStyleConfig.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sonarlint/issuestore/6/8/68bbba69fbc9469ed10568ad6d2fda4fa93abffb

Whitespace-only changes.

src/authentication.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ pub struct Config {
1313
#[derive(Error, Debug)]
1414
pub enum AuthenticationError {
1515
#[error("wrong credentials error")]
16-
WrongCredentialsError,
16+
WrongCredentials,
1717
#[error("no credentials error")]
18-
NoCredentialsError,
18+
NoCredentials,
1919
#[error("request error")]
20-
RequestError(#[from] reqwest::Error),
20+
Request(#[from] reqwest::Error),
2121
#[error("i/o error")]
22-
IoError(#[from] std::io::Error),
22+
Io(#[from] std::io::Error),
2323
#[error("env error")]
24-
EnvError(#[from] env::VarError),
24+
Env(#[from] env::VarError),
2525
#[error("missing home dir error")]
26-
MissingHomeDirError(),
26+
MissingHomeDir(),
2727
#[error("invalid header error")]
28-
InvalidHeaderError(#[from] InvalidHeaderValue),
28+
InvalidHeader(#[from] InvalidHeaderValue),
2929
#[error("unknown error")]
3030
Unknown,
3131
}
@@ -61,9 +61,9 @@ impl Authentication {
6161

6262
match dirs::home_dir() {
6363
Some(path) => {
64-
fs::read_to_string(path.join(".screenly")).map_err(AuthenticationError::IoError)
64+
fs::read_to_string(path.join(".screenly")).map_err(AuthenticationError::Io)
6565
}
66-
None => Err(AuthenticationError::NoCredentialsError),
66+
None => Err(AuthenticationError::NoCredentials),
6767
}
6868
}
6969

@@ -80,7 +80,7 @@ impl Authentication {
8080
fs::write(home.join(".screenly"), token)?;
8181
Ok(())
8282
}
83-
None => Err(AuthenticationError::MissingHomeDirError()),
83+
None => Err(AuthenticationError::MissingHomeDir()),
8484
}
8585
}
8686

@@ -96,7 +96,7 @@ impl Authentication {
9696
.send()?;
9797

9898
match res.status().as_u16() {
99-
401 => Err(AuthenticationError::WrongCredentialsError),
99+
401 => Err(AuthenticationError::WrongCredentials),
100100
404 => Ok(()),
101101
_ => Err(AuthenticationError::Unknown),
102102
}
@@ -115,7 +115,7 @@ impl Authentication {
115115
reqwest::blocking::Client::builder()
116116
.default_headers(default_headers)
117117
.build()
118-
.map_err(AuthenticationError::RequestError)
118+
.map_err(AuthenticationError::Request)
119119
}
120120
}
121121

@@ -184,7 +184,7 @@ mod tests {
184184
}
185185

186186
#[test]
187-
fn test_read_token_when_token_is_overriden_with_env_variable_correct_token_is_returned() {
187+
fn test_read_token_when_token_is_overridden_with_env_variable_correct_token_is_returned() {
188188
let tmp_dir = TempDir::new("test").unwrap();
189189
let _lock = lock_test();
190190
let _token = set_env(OsString::from("API_TOKEN"), "env_token");

src/commands.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ pub trait Formatter {
2323
#[derive(Error, Debug)]
2424
pub enum CommandError {
2525
#[error("auth error")]
26-
AuthenticationError(#[from] AuthenticationError),
26+
Authentication(#[from] AuthenticationError),
2727
#[error("request error")]
28-
RequestError(#[from] reqwest::Error),
28+
Request(#[from] reqwest::Error),
2929
#[error("parse error")]
30-
ParseError(#[from] serde_json::Error),
30+
Parse(#[from] serde_json::Error),
3131
#[error("unknown error #[0]")]
3232
WrongResponseStatus(u16),
3333
#[error("Required field is missing in the response")]
3434
MissingField,
3535
#[error("I/O error #[0]")]
36-
IoError(#[from] std::io::Error),
36+
Io(#[from] std::io::Error),
3737
#[error("Invalid header value")]
3838
InvalidHeaderValue(#[from] InvalidHeaderValue),
3939
}

src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ enum AssetCommands {
108108
},
109109
}
110110

111-
fn handle_command_execution_result<T: commands::Formatter>(
111+
fn handle_command_execution_result<T: Formatter>(
112112
result: anyhow::Result<T, CommandError>,
113113
json: &Option<bool>,
114114
) {
@@ -123,7 +123,7 @@ fn handle_command_execution_result<T: commands::Formatter>(
123123
}
124124
Err(e) => {
125125
match e {
126-
CommandError::AuthenticationError(_) => {
126+
CommandError::Authentication(_) => {
127127
error!(
128128
"Authentication error occurred. Please use login command to authenticate."
129129
)
@@ -196,7 +196,7 @@ fn main() {
196196
}
197197

198198
Err(e) => match e {
199-
AuthenticationError::WrongCredentialsError => {
199+
AuthenticationError::WrongCredentials => {
200200
error!("Token verification failed.");
201201
std::process::exit(1);
202202
}

0 commit comments

Comments
 (0)