summaryrefslogtreecommitdiff
path: root/cli/ops/fs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops/fs.rs')
-rw-r--r--cli/ops/fs.rs203
1 files changed, 100 insertions, 103 deletions
diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs
index 7f9443efb..30e995a44 100644
--- a/cli/ops/fs.rs
+++ b/cli/ops/fs.rs
@@ -2,8 +2,10 @@
// Some deserializer fields are only used on Unix and Windows build fails without it
use super::io::std_file_resource;
use super::io::{FileMetadata, StreamResource, StreamResourceHolder};
+use deno_core::error::custom_error;
+use deno_core::error::type_error;
+use deno_core::error::AnyError;
use deno_core::BufVec;
-use deno_core::ErrBox;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use rand::thread_rng;
@@ -20,6 +22,11 @@ use std::rc::Rc;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
+#[cfg(not(unix))]
+use deno_core::error::generic_error;
+#[cfg(not(unix))]
+use deno_core::error::not_supported;
+
pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_sync(rt, "op_open_sync", op_open_sync);
super::reg_json_async(rt, "op_open_async", op_open_async);
@@ -96,10 +103,10 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
super::reg_json_async(rt, "op_utime_async", op_utime_async);
}
-fn into_string(s: std::ffi::OsString) -> Result<String, ErrBox> {
+fn into_string(s: std::ffi::OsString) -> Result<String, AnyError> {
s.into_string().map_err(|s| {
let message = format!("File name or path {:?} is not valid UTF-8", s);
- ErrBox::new("InvalidData", message)
+ custom_error("InvalidData", message)
})
}
@@ -126,7 +133,7 @@ struct OpenOptions {
fn open_helper(
state: &mut OpState,
args: Value,
-) -> Result<(PathBuf, std::fs::OpenOptions), ErrBox> {
+) -> Result<(PathBuf, std::fs::OpenOptions), AnyError> {
let args: OpenArgs = serde_json::from_value(args)?;
let path = Path::new(&args.path).to_path_buf();
@@ -170,7 +177,7 @@ fn op_open_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let (path, open_options) = open_helper(state, args)?;
let std_file = open_options.open(path)?;
let tokio_file = tokio::fs::File::from_std(std_file);
@@ -188,7 +195,7 @@ async fn op_open_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let (path, open_options) = open_helper(&mut state.borrow_mut(), args)?;
let tokio_file = tokio::fs::OpenOptions::from(open_options)
.open(path)
@@ -211,7 +218,7 @@ struct SeekArgs {
whence: i32,
}
-fn seek_helper(args: Value) -> Result<(u32, SeekFrom), ErrBox> {
+fn seek_helper(args: Value) -> Result<(u32, SeekFrom), AnyError> {
let args: SeekArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
let offset = args.offset;
@@ -222,7 +229,7 @@ fn seek_helper(args: Value) -> Result<(u32, SeekFrom), ErrBox> {
1 => SeekFrom::Current(offset),
2 => SeekFrom::End(offset),
_ => {
- return Err(ErrBox::type_error(format!("Invalid seek mode: {}", whence)));
+ return Err(type_error(format!("Invalid seek mode: {}", whence)));
}
};
@@ -233,11 +240,11 @@ fn op_seek_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let (rid, seek_from) = seek_helper(args)?;
let pos = std_file_resource(state, rid, |r| match r {
- Ok(std_file) => std_file.seek(seek_from).map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error(
+ Ok(std_file) => std_file.seek(seek_from).map_err(AnyError::from),
+ Err(_) => Err(type_error(
"cannot seek on this type of resource".to_string(),
)),
})?;
@@ -248,13 +255,13 @@ async fn op_seek_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let (rid, seek_from) = seek_helper(args)?;
// TODO(ry) This is a fake async op. We need to use poll_fn,
// tokio::fs::File::start_seek and tokio::fs::File::poll_complete
let pos = std_file_resource(&mut state.borrow_mut(), rid, |r| match r {
- Ok(std_file) => std_file.seek(seek_from).map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error(
+ Ok(std_file) => std_file.seek(seek_from).map_err(AnyError::from),
+ Err(_) => Err(type_error(
"cannot seek on this type of resource".to_string(),
)),
})?;
@@ -271,7 +278,7 @@ fn op_fdatasync_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
{
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.fdatasync");
@@ -279,10 +286,8 @@ fn op_fdatasync_sync(
let args: FdatasyncArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
std_file_resource(state, rid, |r| match r {
- Ok(std_file) => std_file.sync_data().map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error(
- "cannot sync this type of resource".to_string(),
- )),
+ Ok(std_file) => std_file.sync_data().map_err(AnyError::from),
+ Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
})?;
Ok(json!({}))
}
@@ -291,16 +296,14 @@ async fn op_fdatasync_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
super::cli_state2(&state).check_unstable("Deno.fdatasync");
let args: FdatasyncArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
std_file_resource(&mut state.borrow_mut(), rid, |r| match r {
- Ok(std_file) => std_file.sync_data().map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error(
- "cannot sync this type of resource".to_string(),
- )),
+ Ok(std_file) => std_file.sync_data().map_err(AnyError::from),
+ Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
})?;
Ok(json!({}))
}
@@ -315,7 +318,7 @@ fn op_fsync_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
{
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.fsync");
@@ -323,10 +326,8 @@ fn op_fsync_sync(
let args: FsyncArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
std_file_resource(state, rid, |r| match r {
- Ok(std_file) => std_file.sync_all().map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error(
- "cannot sync this type of resource".to_string(),
- )),
+ Ok(std_file) => std_file.sync_all().map_err(AnyError::from),
+ Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
})?;
Ok(json!({}))
}
@@ -335,16 +336,14 @@ async fn op_fsync_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
super::cli_state2(&state).check_unstable("Deno.fsync");
let args: FsyncArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
std_file_resource(&mut state.borrow_mut(), rid, |r| match r {
- Ok(std_file) => std_file.sync_all().map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error(
- "cannot sync this type of resource".to_string(),
- )),
+ Ok(std_file) => std_file.sync_all().map_err(AnyError::from),
+ Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
})?;
Ok(json!({}))
}
@@ -359,7 +358,7 @@ fn op_fstat_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
{
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.fstat");
@@ -367,10 +366,8 @@ fn op_fstat_sync(
let args: FstatArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
let metadata = std_file_resource(state, rid, |r| match r {
- Ok(std_file) => std_file.metadata().map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error(
- "cannot stat this type of resource".to_string(),
- )),
+ Ok(std_file) => std_file.metadata().map_err(AnyError::from),
+ Err(_) => Err(type_error("cannot stat this type of resource".to_string())),
})?;
Ok(get_stat_json(metadata).unwrap())
}
@@ -379,17 +376,17 @@ async fn op_fstat_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
super::cli_state2(&state).check_unstable("Deno.fstat");
let args: FstatArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
let metadata =
std_file_resource(&mut state.borrow_mut(), rid, |r| match r {
- Ok(std_file) => std_file.metadata().map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error(
- "cannot stat this type of resource".to_string(),
- )),
+ Ok(std_file) => std_file.metadata().map_err(AnyError::from),
+ Err(_) => {
+ Err(type_error("cannot stat this type of resource".to_string()))
+ }
})?;
Ok(get_stat_json(metadata).unwrap())
}
@@ -403,7 +400,7 @@ fn op_umask(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
{
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.umask");
@@ -415,7 +412,7 @@ fn op_umask(
#[cfg(not(unix))]
{
let _ = args.mask; // avoid unused warning.
- Err(ErrBox::not_supported())
+ Err(not_supported())
}
#[cfg(unix)]
{
@@ -444,7 +441,7 @@ fn op_chdir(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ChdirArgs = serde_json::from_value(args)?;
let d = PathBuf::from(&args.directory);
let cli_state = super::cli_state(state);
@@ -465,7 +462,7 @@ fn op_mkdir_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: MkdirArgs = serde_json::from_value(args)?;
let path = Path::new(&args.path).to_path_buf();
let mode = args.mode.unwrap_or(0o777) & 0o777;
@@ -487,7 +484,7 @@ async fn op_mkdir_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: MkdirArgs = serde_json::from_value(args)?;
let path = Path::new(&args.path).to_path_buf();
let mode = args.mode.unwrap_or(0o777) & 0o777;
@@ -521,7 +518,7 @@ fn op_chmod_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ChmodArgs = serde_json::from_value(args)?;
let path = Path::new(&args.path).to_path_buf();
let mode = args.mode & 0o777;
@@ -541,7 +538,7 @@ fn op_chmod_sync(
{
// Still check file/dir exists on Windows
let _metadata = std::fs::metadata(&path)?;
- Err(ErrBox::error("Not implemented"))
+ Err(generic_error("Not implemented"))
}
}
@@ -549,7 +546,7 @@ async fn op_chmod_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ChmodArgs = serde_json::from_value(args)?;
let path = Path::new(&args.path).to_path_buf();
let mode = args.mode & 0o777;
@@ -570,7 +567,7 @@ async fn op_chmod_async(
{
// Still check file/dir exists on Windows
let _metadata = std::fs::metadata(&path)?;
- Err(ErrBox::not_supported())
+ Err(not_supported())
}
})
.await
@@ -589,7 +586,7 @@ fn op_chown_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ChownArgs = serde_json::from_value(args)?;
let path = Path::new(&args.path).to_path_buf();
let cli_state = super::cli_state(state);
@@ -611,7 +608,7 @@ fn op_chown_sync(
// TODO Implement chown for Windows
#[cfg(not(unix))]
{
- Err(ErrBox::error("Not implemented"))
+ Err(generic_error("Not implemented"))
}
}
@@ -619,7 +616,7 @@ async fn op_chown_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ChownArgs = serde_json::from_value(args)?;
let path = Path::new(&args.path).to_path_buf();
@@ -642,7 +639,7 @@ async fn op_chown_async(
}
// TODO Implement chown for Windows
#[cfg(not(unix))]
- Err(ErrBox::not_supported())
+ Err(not_supported())
})
.await
.unwrap()
@@ -659,7 +656,7 @@ fn op_remove_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: RemoveArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
let recursive = args.recursive;
@@ -703,7 +700,7 @@ async fn op_remove_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: RemoveArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
let recursive = args.recursive;
@@ -757,7 +754,7 @@ fn op_copy_file_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: CopyFileArgs = serde_json::from_value(args)?;
let from = PathBuf::from(&args.from);
let to = PathBuf::from(&args.to);
@@ -771,7 +768,7 @@ fn op_copy_file_sync(
// See https://github.com/rust-lang/rust/issues/54800
// Once the issue is resolved, we should remove this workaround.
if cfg!(unix) && !from.is_file() {
- return Err(ErrBox::new("NotFound", "File not found"));
+ return Err(custom_error("NotFound", "File not found"));
}
// returns size of from as u64 (we ignore)
@@ -783,7 +780,7 @@ async fn op_copy_file_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: CopyFileArgs = serde_json::from_value(args)?;
let from = PathBuf::from(&args.from);
let to = PathBuf::from(&args.to);
@@ -798,7 +795,7 @@ async fn op_copy_file_async(
// See https://github.com/rust-lang/rust/issues/54800
// Once the issue is resolved, we should remove this workaround.
if cfg!(unix) && !from.is_file() {
- return Err(ErrBox::new("NotFound", "File not found"));
+ return Err(custom_error("NotFound", "File not found"));
}
// returns size of from as u64 (we ignore)
@@ -825,7 +822,7 @@ fn to_msec(maybe_time: Result<SystemTime, io::Error>) -> Value {
}
#[inline(always)]
-fn get_stat_json(metadata: std::fs::Metadata) -> Result<Value, ErrBox> {
+fn get_stat_json(metadata: std::fs::Metadata) -> Result<Value, AnyError> {
// Unix stat member (number types only). 0 if not on unix.
macro_rules! usm {
($member:ident) => {{
@@ -878,7 +875,7 @@ fn op_stat_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: StatArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
let lstat = args.lstat;
@@ -897,7 +894,7 @@ async fn op_stat_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: StatArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
let lstat = args.lstat;
@@ -927,7 +924,7 @@ fn op_realpath_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: RealpathArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
@@ -953,7 +950,7 @@ async fn op_realpath_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: RealpathArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
@@ -989,7 +986,7 @@ fn op_read_dir_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ReadDirArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
@@ -1022,7 +1019,7 @@ async fn op_read_dir_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ReadDirArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
super::cli_state2(&state).check_read(&path)?;
@@ -1063,7 +1060,7 @@ fn op_rename_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: RenameArgs = serde_json::from_value(args)?;
let oldpath = PathBuf::from(&args.oldpath);
let newpath = PathBuf::from(&args.newpath);
@@ -1081,7 +1078,7 @@ async fn op_rename_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: RenameArgs = serde_json::from_value(args)?;
let oldpath = PathBuf::from(&args.oldpath);
let newpath = PathBuf::from(&args.newpath);
@@ -1115,7 +1112,7 @@ fn op_link_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.link");
let args: LinkArgs = serde_json::from_value(args)?;
@@ -1134,7 +1131,7 @@ async fn op_link_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let cli_state = super::cli_state2(&state);
cli_state.check_unstable("Deno.link");
@@ -1174,7 +1171,7 @@ fn op_symlink_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.symlink");
let args: SymlinkArgs = serde_json::from_value(args)?;
@@ -1202,7 +1199,7 @@ fn op_symlink_sync(
Some(options) => match options._type.as_ref() {
"file" => symlink_file(&oldpath, &newpath)?,
"dir" => symlink_dir(&oldpath, &newpath)?,
- _ => return Err(ErrBox::type_error("unsupported type")),
+ _ => return Err(type_error("unsupported type")),
},
None => {
let old_meta = std::fs::metadata(&oldpath);
@@ -1214,7 +1211,7 @@ fn op_symlink_sync(
symlink_dir(&oldpath, &newpath)?
}
}
- Err(_) => return Err(ErrBox::type_error("you must pass a `options` argument for non-existent target path in windows".to_string())),
+ Err(_) => return Err(type_error("you must pass a `options` argument for non-existent target path in windows".to_string())),
}
}
};
@@ -1226,7 +1223,7 @@ async fn op_symlink_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let cli_state = super::cli_state2(&state);
cli_state.check_unstable("Deno.symlink");
@@ -1252,7 +1249,7 @@ async fn op_symlink_async(
Some(options) => match options._type.as_ref() {
"file" => symlink_file(&oldpath, &newpath)?,
"dir" => symlink_dir(&oldpath, &newpath)?,
- _ => return Err(ErrBox::type_error("unsupported type")),
+ _ => return Err(type_error("unsupported type")),
},
None => {
let old_meta = std::fs::metadata(&oldpath);
@@ -1264,7 +1261,7 @@ async fn op_symlink_async(
symlink_dir(&oldpath, &newpath)?
}
}
- Err(_) => return Err(ErrBox::type_error("you must pass a `options` argument for non-existent target path in windows".to_string())),
+ Err(_) => return Err(type_error("you must pass a `options` argument for non-existent target path in windows".to_string())),
}
}
};
@@ -1285,7 +1282,7 @@ fn op_read_link_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ReadLinkArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
@@ -1302,7 +1299,7 @@ async fn op_read_link_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: ReadLinkArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
super::cli_state2(&state).check_read(&path)?;
@@ -1327,7 +1324,7 @@ fn op_ftruncate_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
{
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.ftruncate");
@@ -1336,8 +1333,8 @@ fn op_ftruncate_sync(
let rid = args.rid as u32;
let len = args.len as u64;
std_file_resource(state, rid, |r| match r {
- Ok(std_file) => std_file.set_len(len).map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error("cannot truncate this type of resource")),
+ Ok(std_file) => std_file.set_len(len).map_err(AnyError::from),
+ Err(_) => Err(type_error("cannot truncate this type of resource")),
})?;
Ok(json!({}))
}
@@ -1346,14 +1343,14 @@ async fn op_ftruncate_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
super::cli_state2(&state).check_unstable("Deno.ftruncate");
let args: FtruncateArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
let len = args.len as u64;
std_file_resource(&mut state.borrow_mut(), rid, |r| match r {
- Ok(std_file) => std_file.set_len(len).map_err(ErrBox::from),
- Err(_) => Err(ErrBox::type_error("cannot truncate this type of resource")),
+ Ok(std_file) => std_file.set_len(len).map_err(AnyError::from),
+ Err(_) => Err(type_error("cannot truncate this type of resource")),
})?;
Ok(json!({}))
}
@@ -1369,7 +1366,7 @@ fn op_truncate_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: TruncateArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
let len = args.len;
@@ -1387,7 +1384,7 @@ async fn op_truncate_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: TruncateArgs = serde_json::from_value(args)?;
let path = PathBuf::from(&args.path);
let len = args.len;
@@ -1459,7 +1456,7 @@ fn op_make_temp_dir_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: MakeTempArgs = serde_json::from_value(args)?;
let dir = args.dir.map(|s| PathBuf::from(&s));
@@ -1488,7 +1485,7 @@ async fn op_make_temp_dir_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: MakeTempArgs = serde_json::from_value(args)?;
let dir = args.dir.map(|s| PathBuf::from(&s));
@@ -1521,7 +1518,7 @@ fn op_make_temp_file_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: MakeTempArgs = serde_json::from_value(args)?;
let dir = args.dir.map(|s| PathBuf::from(&s));
@@ -1550,7 +1547,7 @@ async fn op_make_temp_file_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let args: MakeTempArgs = serde_json::from_value(args)?;
let dir = args.dir.map(|s| PathBuf::from(&s));
@@ -1592,7 +1589,7 @@ fn op_futime_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
{
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.futimeSync");
@@ -1605,9 +1602,9 @@ fn op_futime_sync(
std_file_resource(state, rid, |r| match r {
Ok(std_file) => {
filetime::set_file_handle_times(std_file, Some(atime), Some(mtime))
- .map_err(ErrBox::from)
+ .map_err(AnyError::from)
}
- Err(_) => Err(ErrBox::type_error(
+ Err(_) => Err(type_error(
"cannot futime on this type of resource".to_string(),
)),
})?;
@@ -1619,7 +1616,7 @@ async fn op_futime_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let mut state = state.borrow_mut();
let cli_state = super::cli_state(&state);
cli_state.check_unstable("Deno.futime");
@@ -1631,9 +1628,9 @@ async fn op_futime_async(
std_file_resource(&mut state, rid, |r| match r {
Ok(std_file) => {
filetime::set_file_handle_times(std_file, Some(atime), Some(mtime))
- .map_err(ErrBox::from)
+ .map_err(AnyError::from)
}
- Err(_) => Err(ErrBox::type_error(
+ Err(_) => Err(type_error(
"cannot futime on this type of resource".to_string(),
)),
})?;
@@ -1653,7 +1650,7 @@ fn op_utime_sync(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let cli_state = super::cli_state(state);
cli_state.check_unstable("Deno.utime");
@@ -1671,7 +1668,7 @@ async fn op_utime_async(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let state = state.borrow();
let cli_state = super::cli_state(&state);
cli_state.check_unstable("Deno.utime");
@@ -1695,7 +1692,7 @@ fn op_cwd(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, ErrBox> {
+) -> Result<Value, AnyError> {
let path = current_dir()?;
let cli_state = super::cli_state(state);
cli_state.check_read_blind(&path, "CWD")?;