Skip to content

Commit a716f65

Browse files
committed
fix(credential)!: Decouple ErrorKind from BoxError
BREAKING CHANGE: `Error` because an opaque type with the enum broken out into `ErrorKind` - To construct an error from an `ErrorKind`, you can use `Into`. - To wrap an existing error, use `Error::other`
1 parent 5c142dd commit a716f65

File tree

19 files changed

+197
-125
lines changed

19 files changed

+197
-125
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ anyhow = "1.0.80"
2525
base64 = "0.21.7"
2626
bytesize = "1.3"
2727
cargo = { path = "" }
28-
cargo-credential = { version = "0.4.2", path = "credential/cargo-credential" }
29-
cargo-credential-libsecret = { version = "0.4.2", path = "credential/cargo-credential-libsecret" }
30-
cargo-credential-macos-keychain = { version = "0.4.2", path = "credential/cargo-credential-macos-keychain" }
31-
cargo-credential-wincred = { version = "0.4.2", path = "credential/cargo-credential-wincred" }
28+
cargo-credential = { version = "0.5.0", path = "credential/cargo-credential" }
29+
cargo-credential-libsecret = { version = "0.5.0", path = "credential/cargo-credential-libsecret" }
30+
cargo-credential-macos-keychain = { version = "0.5.0", path = "credential/cargo-credential-macos-keychain" }
31+
cargo-credential-wincred = { version = "0.5.0", path = "credential/cargo-credential-wincred" }
3232
cargo-platform = { path = "crates/cargo-platform", version = "0.1.5" }
3333
cargo-test-macro = { path = "crates/cargo-test-macro" }
3434
cargo-test-support = { path = "crates/cargo-test-support" }

credential/cargo-credential-1password/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential-1password"
3-
version = "0.4.4"
3+
version = "0.5.0"
44
rust-version.workspace = true
55
edition.workspace = true
66
license.workspace = true

credential/cargo-credential-1password/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![allow(clippy::print_stderr)]
55

66
use cargo_credential::{
7-
Action, CacheControl, Credential, CredentialResponse, Error, RegistryInfo, Secret,
7+
Action, CacheControl, Credential, CredentialResponse, Error, ErrorKind, RegistryInfo, Secret,
88
};
99
use serde::Deserialize;
1010
use std::io::Read;
@@ -278,7 +278,7 @@ impl Credential for OnePasswordCredential {
278278
operation_independent: true,
279279
})
280280
} else {
281-
Err(Error::NotFound)
281+
Err(ErrorKind::NotFound.into())
282282
}
283283
}
284284
Action::Login(options) => {
@@ -301,10 +301,10 @@ impl Credential for OnePasswordCredential {
301301
op.delete(&session, &id)?;
302302
Ok(CredentialResponse::Logout)
303303
} else {
304-
Err(Error::NotFound)
304+
Err(ErrorKind::NotFound.into())
305305
}
306306
}
307-
_ => Err(Error::OperationNotSupported),
307+
_ => Err(ErrorKind::OperationNotSupported.into()),
308308
}
309309
}
310310
}

credential/cargo-credential-libsecret/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential-libsecret"
3-
version = "0.4.4"
3+
version = "0.5.0"
44
rust-version = "1.76.0" # MSRV:1
55
edition.workspace = true
66
license.workspace = true

credential/cargo-credential-libsecret/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ mod linux {
44
55
use anyhow::Context;
66
use cargo_credential::{
7-
read_token, Action, CacheControl, Credential, CredentialResponse, Error, RegistryInfo,
8-
Secret,
7+
read_token, Action, CacheControl, Credential, CredentialResponse, Error, ErrorKind,
8+
RegistryInfo, Secret,
99
};
1010
use libloading::{Library, Symbol};
1111
use std::ffi::{CStr, CString};
@@ -153,7 +153,7 @@ mod linux {
153153
.into());
154154
}
155155
if token_c.is_null() {
156-
return Err(Error::NotFound);
156+
return Err(ErrorKind::NotFound.into());
157157
}
158158
let token = Secret::from(
159159
CStr::from_ptr(token_c)
@@ -223,7 +223,7 @@ mod linux {
223223
}
224224
Ok(CredentialResponse::Logout)
225225
}
226-
_ => Err(Error::OperationNotSupported),
226+
_ => Err(ErrorKind::OperationNotSupported.into()),
227227
}
228228
}
229229
}

credential/cargo-credential-macos-keychain/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential-macos-keychain"
3-
version = "0.4.4"
3+
version = "0.5.0"
44
rust-version = "1.76.0" # MSRV:1
55
edition.workspace = true
66
license.workspace = true

credential/cargo-credential-macos-keychain/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#[cfg(target_os = "macos")]
66
mod macos {
77
use cargo_credential::{
8-
read_token, Action, CacheControl, Credential, CredentialResponse, Error, RegistryInfo,
8+
read_token, Action, CacheControl, Credential, CredentialResponse, Error, ErrorKind,
9+
RegistryInfo,
910
};
1011
use security_framework::os::macos::keychain::SecKeychain;
1112

@@ -31,7 +32,7 @@ mod macos {
3132
let not_found = security_framework::base::Error::from(NOT_FOUND).code();
3233
match action {
3334
Action::Get(_) => match keychain.find_generic_password(&service_name, ACCOUNT) {
34-
Err(e) if e.code() == not_found => Err(Error::NotFound),
35+
Err(e) if e.code() == not_found => Err(ErrorKind::NotFound.into()),
3536
Err(e) => Err(Box::new(e).into()),
3637
Ok((pass, _)) => {
3738
let token = String::from_utf8(pass.as_ref().to_vec()).map_err(Box::new)?;
@@ -64,14 +65,14 @@ mod macos {
6465
Ok(CredentialResponse::Login)
6566
}
6667
Action::Logout => match keychain.find_generic_password(&service_name, ACCOUNT) {
67-
Err(e) if e.code() == not_found => Err(Error::NotFound),
68+
Err(e) if e.code() == not_found => Err(ErrorKind::NotFound.into()),
6869
Err(e) => Err(Box::new(e).into()),
6970
Ok((_, item)) => {
7071
item.delete();
7172
Ok(CredentialResponse::Logout)
7273
}
7374
},
74-
_ => Err(Error::OperationNotSupported),
75+
_ => Err(ErrorKind::OperationNotSupported.into()),
7576
}
7677
}
7778
}

credential/cargo-credential-wincred/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential-wincred"
3-
version = "0.4.4"
3+
version = "0.5.0"
44
rust-version = "1.76.0" # MSRV:1
55
edition.workspace = true
66
license.workspace = true

credential/cargo-credential-wincred/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[cfg(windows)]
44
mod win {
55
use cargo_credential::{read_token, Action, CacheControl, CredentialResponse, RegistryInfo};
6-
use cargo_credential::{Credential, Error};
6+
use cargo_credential::{Credential, Error, ErrorKind};
77
use std::ffi::OsStr;
88

99
use std::os::windows::ffi::OsStrExt;
@@ -56,7 +56,7 @@ mod win {
5656
{
5757
let err = std::io::Error::last_os_error();
5858
if err.raw_os_error() == Some(ERROR_NOT_FOUND as i32) {
59-
return Err(Error::NotFound);
59+
return Err(ErrorKind::NotFound.into());
6060
}
6161
return Err(Box::new(err).into());
6262
}
@@ -107,13 +107,13 @@ mod win {
107107
if result != TRUE {
108108
let err = std::io::Error::last_os_error();
109109
if err.raw_os_error() == Some(ERROR_NOT_FOUND as i32) {
110-
return Err(Error::NotFound);
110+
return Err(ErrorKind::NotFound.into());
111111
}
112112
return Err(Box::new(err).into());
113113
}
114114
Ok(CredentialResponse::Logout)
115115
}
116-
_ => Err(Error::OperationNotSupported),
116+
_ => Err(ErrorKind::OperationNotSupported.into()),
117117
}
118118
}
119119
}

0 commit comments

Comments
 (0)