Skip to content

Commit 950da22

Browse files
authored
Remove the use of anyhow (#169)
* Remove the use of anyhow * run fmt
1 parent c35f348 commit 950da22

File tree

22 files changed

+153
-139
lines changed

22 files changed

+153
-139
lines changed

Cargo.lock

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

crates/deno_task_shell/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ shell = ["futures", "glob", "os_pipe", "path-dedot", "tokio", "tokio-util"]
1515
serialization = ["serde"]
1616

1717
[dependencies]
18-
anyhow = "1.0.87"
1918
futures = { version = "0.3.30", optional = true }
2019
glob = { version = "0.3.1", optional = true }
2120
path-dedot = { version = "3.1.1", optional = true }

crates/deno_task_shell/src/shell/commands/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2018-2024 the Deno authors. MIT license.
22

3-
use anyhow::bail;
4-
use anyhow::Result;
3+
use miette::bail;
4+
use miette::Result;
55

66
#[derive(Debug, PartialEq, Eq)]
77
pub enum ArgKind<'a> {

crates/deno_task_shell/src/shell/commands/cat.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright 2018-2024 the Deno authors. MIT license.
22

3-
use anyhow::Result;
43
use futures::future::LocalBoxFuture;
4+
use miette::IntoDiagnostic;
5+
use miette::Result;
56
use std::fs::File;
67
use std::io::IsTerminal;
78
use std::io::Read;
@@ -52,7 +53,7 @@ fn execute_cat(mut context: ShellCommandContext) -> Result<ExecuteResult> {
5253
return Ok(ExecuteResult::for_cancellation());
5354
}
5455

55-
let size = file.read(&mut buf)?;
56+
let size = file.read(&mut buf).into_diagnostic()?;
5657
if size == 0 {
5758
break;
5859
} else {

crates/deno_task_shell/src/shell/commands/cd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use std::path::Path;
44
use std::path::PathBuf;
55

6-
use anyhow::bail;
7-
use anyhow::Result;
86
use futures::future::LocalBoxFuture;
7+
use miette::bail;
8+
use miette::Result;
99
use path_dedot::ParseDot;
1010

1111
use crate::shell::fs_util;
@@ -47,7 +47,7 @@ fn execute_cd(cwd: &Path, args: Vec<String>) -> Result<PathBuf> {
4747
let path = parse_args(args.clone())?;
4848
let new_dir = if path == "~" {
4949
dirs::home_dir()
50-
.ok_or_else(|| anyhow::anyhow!("Home directory not found"))?
50+
.ok_or_else(|| miette::miette!("Home directory not found"))?
5151
} else {
5252
cwd.join(&path)
5353
};

crates/deno_task_shell/src/shell/commands/cp_mv.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
use std::path::Path;
44
use std::path::PathBuf;
55

6-
use anyhow::bail;
7-
use anyhow::Context;
8-
use anyhow::Result;
96
use futures::future::BoxFuture;
107
use futures::future::LocalBoxFuture;
118
use futures::FutureExt;
9+
use miette::bail;
10+
use miette::Context;
11+
use miette::IntoDiagnostic;
12+
use miette::Result;
1213

1314
use crate::shell::types::ExecuteResult;
1415
use crate::shell::types::ShellPipeWriter;
@@ -87,7 +88,9 @@ async fn do_copy_operation(
8788
bail!("source was a directory; maybe specify -r")
8889
}
8990
} else {
90-
tokio::fs::copy(&from.path, &to.path).await?;
91+
tokio::fs::copy(&from.path, &to.path)
92+
.await
93+
.into_diagnostic()?;
9194
}
9295
Ok(())
9396
}
@@ -100,13 +103,15 @@ fn copy_dir_recursively(
100103
async move {
101104
tokio::fs::create_dir_all(&to)
102105
.await
103-
.with_context(|| format!("Creating {}", to.display()))?;
106+
.into_diagnostic()
107+
.context(miette::miette!("Creating {}", to.display()))?;
104108
let mut read_dir = tokio::fs::read_dir(&from)
105109
.await
106-
.with_context(|| format!("Reading {}", from.display()))?;
110+
.into_diagnostic()
111+
.context(miette::miette!("Reading {}", from.display()))?;
107112

108-
while let Some(entry) = read_dir.next_entry().await? {
109-
let file_type = entry.file_type().await?;
113+
while let Some(entry) = read_dir.next_entry().await.into_diagnostic()? {
114+
let file_type = entry.file_type().await.into_diagnostic()?;
110115
let new_from = from.join(entry.file_name());
111116
let new_to = to.join(entry.file_name());
112117

@@ -117,9 +122,12 @@ fn copy_dir_recursively(
117122
format!("Dir {} to {}", new_from.display(), new_to.display())
118123
})?;
119124
} else if file_type.is_file() {
120-
tokio::fs::copy(&new_from, &new_to).await.with_context(|| {
121-
format!("Copying {} to {}", new_from.display(), new_to.display())
122-
})?;
125+
tokio::fs::copy(&new_from, &new_to)
126+
.await
127+
.into_diagnostic()
128+
.with_context(|| {
129+
format!("Copying {} to {}", new_from.display(), new_to.display())
130+
})?;
123131
}
124132
}
125133

crates/deno_task_shell/src/shell/commands/exit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2018-2024 the Deno authors. MIT license.
22

3-
use anyhow::bail;
4-
use anyhow::Result;
53
use futures::future::LocalBoxFuture;
4+
use miette::bail;
5+
use miette::Result;
66

77
use crate::shell::types::ExecuteResult;
88

crates/deno_task_shell/src/shell/commands/head.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
use std::fs::File;
44
use std::io::Read;
55

6-
use anyhow::bail;
7-
use anyhow::Result;
86
use futures::future::LocalBoxFuture;
7+
use miette::bail;
8+
use miette::IntoDiagnostic;
9+
use miette::Result;
910
use tokio_util::sync::CancellationToken;
1011

1112
use crate::ExecuteResult;
@@ -96,7 +97,7 @@ fn execute_head(mut context: ShellCommandContext) -> Result<ExecuteResult> {
9697
&mut context.stdout,
9798
flags.lines,
9899
context.state.token(),
99-
|buf| file.read(buf).map_err(Into::into),
100+
|buf| file.read(buf).into_diagnostic(),
100101
512,
101102
),
102103
Err(err) => {
@@ -131,15 +132,15 @@ fn parse_args(args: Vec<String>) -> Result<HeadFlags> {
131132
}
132133
ArgKind::ShortFlag('n') => match iterator.next() {
133134
Some(ArgKind::Arg(arg)) => {
134-
lines = Some(arg.parse::<u64>()?);
135+
lines = Some(arg.parse::<u64>().into_diagnostic()?);
135136
}
136137
_ => bail!("expected a value following -n"),
137138
},
138139
ArgKind::LongFlag(flag) => {
139140
if flag == "lines" || flag == "lines=" {
140141
bail!("expected a value for --lines");
141142
} else if let Some(arg) = flag.strip_prefix("lines=") {
142-
lines = Some(arg.parse::<u64>()?);
143+
lines = Some(arg.parse::<u64>().into_diagnostic()?);
143144
} else {
144145
arg.bail_unsupported()?
145146
}

crates/deno_task_shell/src/shell/commands/mkdir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright 2018-2024 the Deno authors. MIT license.
22

3-
use anyhow::bail;
4-
use anyhow::Result;
53
use futures::future::LocalBoxFuture;
64
use futures::FutureExt;
5+
use miette::bail;
6+
use miette::Result;
77
use std::path::Path;
88

99
use crate::shell::types::ExecuteResult;

crates/deno_task_shell/src/shell/commands/pwd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2018-2024 the Deno authors. MIT license.
22

3-
use anyhow::Context;
4-
use anyhow::Result;
53
use futures::future::LocalBoxFuture;
4+
use miette::Context;
5+
use miette::Result;
66
use std::path::Path;
77

88
use crate::shell::fs_util;

0 commit comments

Comments
 (0)