Skip to content

Commit 833b884

Browse files
Merge pull request #520 from SierraSoftworks/copilot/fix-deprecated-method-usage
Replace deprecated `wrap_err_as_user`/`wrap_err_as_system` with `wrap_user_err`/`wrap_system_err`
2 parents ecbd0e0 + aeb35fc commit 833b884

5 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ impl TryFrom<&Args> for Config {
1717
type Error = human_errors::Error;
1818

1919
fn try_from(value: &Args) -> Result<Self, Self::Error> {
20-
let content = std::fs::read_to_string(&value.config).wrap_err_as_user(
20+
let content = std::fs::read_to_string(&value.config).wrap_user_err(
2121
format!("Failed to read the config file {}.", &value.config),
2222
&["Make sure that the configuration file exists and can be ready by the process."],
2323
)?;
24-
let config: Config = serde_yaml::from_str(&content).wrap_err_as_user(
24+
let config: Config = serde_yaml::from_str(&content).wrap_user_err(
2525
"Failed to parse your configuration file, as it is not recognized as valid YAML.",
2626
&["Make sure that your configuration file is formatted correctly."],
2727
)?;

src/engines/git.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl BackupEngine<GitRepo> for GitEngine {
5252
impl GitEngine {
5353
fn ensure_directory(&self, path: &Path) -> Result<(), human_errors::Error> {
5454
trace!("Ensuring directory exists: {}", path.display());
55-
std::fs::create_dir_all(path).wrap_err_as_user(
55+
std::fs::create_dir_all(path).wrap_user_err(
5656
format!("Unable to create backup directory '{}'", path.display()),
5757
&["Make sure that you have permission to create the directory."],
5858
)
@@ -70,7 +70,7 @@ impl GitEngine {
7070
repo.clone_url,
7171
target.display()
7272
);
73-
let mut fetch = gix::prepare_clone(repo.clone_url.as_str(), target).wrap_err_as_system(
73+
let mut fetch = gix::prepare_clone(repo.clone_url.as_str(), target).wrap_system_err(
7474
format!("Failed to clone the repository {}.", &repo.clone_url),
7575
&["Please make sure that the target directory is writable and that the repository is accessible."],
7676
)?;
@@ -87,7 +87,7 @@ impl GitEngine {
8787
}
8888

8989
trace!("Running clone in bare mode (not checking out files)");
90-
let (repository, _outcome) = fetch.fetch_only(Discard, cancel).wrap_err_as_system(
90+
let (repository, _outcome) = fetch.fetch_only(Discard, cancel).wrap_system_err(
9191
format!("Unable to clone remote repository '{}'", repo.clone_url),
9292
&["Make sure that your internet connectivity is working correctly, and that your local git configuration is able to clone this repo."],
9393
)?;
@@ -97,15 +97,15 @@ impl GitEngine {
9797

9898
trace!("Configuring core.bare for Git repository");
9999
self.update_config(&repository, |c| {
100-
c.set_raw_value(&gix::config::tree::Core::BARE, "true").wrap_err_as_system(
100+
c.set_raw_value(&gix::config::tree::Core::BARE, "true").wrap_system_err(
101101
format!("Unable to set the 'core.bare' configuration option for repository '{}'", repo.name()),
102102
&["Make sure that the git repository has been correctly initialized and run `git config core.bare true` to configure it correctly."],
103103
)?;
104104

105105
Ok(())
106106
})?;
107107

108-
let head_id = repository.head_id().wrap_err_as_user(
108+
let head_id = repository.head_id().wrap_user_err(
109109
format!("The repository '{}' did not have a valid HEAD, which may indicate that there is something wrong with the source repository.", &repo.clone_url),
110110
&["Make sure that the remote repository is valid."],
111111
)?;
@@ -121,7 +121,7 @@ impl GitEngine {
121121
cancel: &AtomicBool,
122122
) -> Result<BackupState, human_errors::Error> {
123123
trace!("Opening repository {}", target.display());
124-
let repository = gix::open(target).wrap_err_as_user(
124+
let repository = gix::open(target).wrap_user_err(
125125
format!(
126126
"Failed to open the repository '{}' at '{}'",
127127
&repo.clone_url,
@@ -140,7 +140,7 @@ impl GitEngine {
140140
"Configuring fetch operation for repository {}",
141141
target.display()
142142
);
143-
let remote = repository.find_fetch_remote(Some(repo.clone_url.as_str().into())).wrap_err_as_user(
143+
let remote = repository.find_fetch_remote(Some(repo.clone_url.as_str().into())).wrap_user_err(
144144
format!(
145145
"Failed to find the remote '{}' in the repository '{}'",
146146
repo.clone_url,
@@ -155,7 +155,7 @@ impl GitEngine {
155155
.map(|s| gix::bstr::BString::from(s.as_str()))
156156
.collect::<Vec<gix::bstr::BString>>(),
157157
gix::remote::Direction::Fetch)
158-
.wrap_err_as_user(
158+
.wrap_user_err(
159159
format!(
160160
"Failed to configure the remote '{}' in the repository '{}' to fetch all branches.",
161161
&repo.clone_url,
@@ -167,7 +167,7 @@ impl GitEngine {
167167
trace!("Connecting to remote repository {}", repo.clone_url);
168168
let mut connection = remote
169169
.connect(gix::remote::Direction::Fetch)
170-
.wrap_err_as_user(
170+
.wrap_user_err(
171171
format!(
172172
"Unable to establish connection to remote git repository '{}'",
173173
&repo.clone_url
@@ -183,7 +183,7 @@ impl GitEngine {
183183
);
184184
connection
185185
.prepare_fetch(Discard, Default::default())
186-
.wrap_err_as_user(
186+
.wrap_user_err(
187187
format!(
188188
"Unable to prepare fetch from remote git repository '{}'",
189189
&repo.clone_url
@@ -192,15 +192,15 @@ impl GitEngine {
192192
)?
193193
.with_write_packed_refs_only(true)
194194
.receive(Discard, cancel)
195-
.wrap_err_as_user(
195+
.wrap_user_err(
196196
format!(
197197
"Unable to fetch from remote git repository '{}'",
198198
&repo.clone_url
199199
),
200200
&["Make sure that the repository is available and correctly configured."],
201201
)?;
202202

203-
let head_id = repository.head_id().wrap_err_as_user(
203+
let head_id = repository.head_id().wrap_user_err(
204204
format!("The repository '{}' did not have a valid HEAD, which may indicate that there is something wrong with the source repository.", &repo.clone_url),
205205
&["Make sure that the remote repository is valid."],
206206
)?;
@@ -286,7 +286,7 @@ impl GitEngine {
286286
repo.path().join("config"),
287287
gix::config::Source::Local,
288288
)
289-
.wrap_err_as_system(
289+
.wrap_system_err(
290290
format!(
291291
"Unable to load git configuration for repository '{}'",
292292
repo.path().display()
@@ -296,15 +296,15 @@ impl GitEngine {
296296

297297
update(&mut config)?;
298298

299-
let mut file = std::fs::File::create(repo.path().join("config")).wrap_err_as_system(
299+
let mut file = std::fs::File::create(repo.path().join("config")).wrap_system_err(
300300
format!(
301301
"Unable to write git configuration for repository '{}'",
302302
repo.path().display()
303303
),
304304
&["Make sure that the git repository has been correctly initialized."],
305305
)?;
306306

307-
config.write_to(&mut file).wrap_err_as_system(
307+
config.write_to(&mut file).wrap_system_err(
308308
format!(
309309
"Unable to write git configuration for repository '{}'",
310310
repo.path().display()

src/engines/http_file.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl HttpFileEngine {
2929
}
3030

3131
fn ensure_directory(&self, path: &Path) -> Result<(), human_errors::Error> {
32-
std::fs::create_dir_all(path).wrap_err_as_user(
32+
std::fs::create_dir_all(path).wrap_user_err(
3333
format!("Unable to create backup directory '{}'", path.display()),
3434
&["Make sure that you have permission to create the directory."],
3535
)
@@ -138,7 +138,7 @@ impl BackupEngine<HttpFile> for HttpFileEngine {
138138

139139
let mut file = tokio::fs::File::create(temp_path.as_path())
140140
.await
141-
.wrap_err_as_user(
141+
.wrap_user_err(
142142
format!(
143143
"Unable to create temporary backup file '{}'.",
144144
temp_path.as_path().display()
@@ -209,7 +209,7 @@ impl BackupEngine<HttpFile> for HttpFileEngine {
209209
}
210210

211211
let state = if target_path.exists() {
212-
tokio::fs::remove_file(&target_path).await.wrap_err_as_user(
212+
tokio::fs::remove_file(&target_path).await.wrap_user_err(
213213
format!("Unable to remove original backup file '{}' prior to replacement with new file.", target_path.display()),
214214
&["Make sure that you have write (and delete) permission on the backup directory and try again."],
215215
)?;
@@ -245,7 +245,7 @@ impl BackupEngine<HttpFile> for HttpFileEngine {
245245
format!("{:x}", shasum),
246246
)
247247
.await
248-
.wrap_err_as_user(
248+
.wrap_user_err(
249249
format!(
250250
"Unable to write SHA-256 checksum file for backup file '{}'.",
251251
target_path.display()

src/filter/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'a, I: Iterator<Item = Result<Token<'a>, Error>>> Parser<'a, I> {
170170
match self.tokens.next() {
171171
Some(Ok(Token::True(..))) => Ok(true.into()),
172172
Some(Ok(Token::False(..))) => Ok(false.into()),
173-
Some(Ok(Token::Number(loc, n))) => Ok(FilterValue::Number(n.parse().wrap_err_as_user(
173+
Some(Ok(Token::Number(loc, n))) => Ok(FilterValue::Number(n.parse().wrap_user_err(
174174
format!("Failed to parse the number '{n}' which you provided at {}.", loc),
175175
&["Please make sure that the number is well formatted. It should be in the form 123, or 123.45."],
176176
)?)),

src/helpers/github.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ impl GitHubClient {
6161
let resp = self.call(Method::GET, &url, creds, |r| r, cancel).await?;
6262

6363
if let Some(link_header) = resp.headers().get(LINK) {
64-
let link_header = link_header.to_str().wrap_err_as_system(
64+
let link_header = link_header.to_str().wrap_system_err(
6565
"Unable to parse GitHub's Link header due to invalid characters, which will result in pagination failing to work correctly.",
6666
&["Please report this issue to us on GitHub."])?;
6767

68-
let links = parse_link_header::parse_with_rel(link_header).wrap_err_as_system(
68+
let links = parse_link_header::parse_with_rel(link_header).wrap_system_err(
6969
"Unable to parse GitHub's Link header, which will result in pagination failing to work correctly.",
7070
&["Please report this issue to us on GitHub."])?;
7171

@@ -107,7 +107,7 @@ impl GitHubClient {
107107
where
108108
B: FnOnce(reqwest::RequestBuilder) -> reqwest::RequestBuilder,
109109
{
110-
let parsed_url: Url = url.as_ref().parse().wrap_err_as_user(
110+
let parsed_url: Url = url.as_ref().parse().wrap_user_err(
111111
format!(
112112
"Unable to parse GitHub URL '{}' as a valid URL.",
113113
url.as_ref()

0 commit comments

Comments
 (0)