mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
Remove some more unnecessary 'to_string()' calls (#7190)
This commit is contained in:
parent
9bfb0df805
commit
aead9dc91e
10 changed files with 42 additions and 67 deletions
|
@ -44,12 +44,9 @@ pub fn create_http_client(ca_file: Option<&str>) -> Result<Client, ErrBox> {
|
|||
builder = builder.add_root_certificate(cert);
|
||||
}
|
||||
|
||||
builder.build().map_err(|_| {
|
||||
ErrBox::from(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Unable to build http client".to_string(),
|
||||
))
|
||||
})
|
||||
builder
|
||||
.build()
|
||||
.map_err(|_| ErrBox::error("Unable to build http client"))
|
||||
}
|
||||
/// Construct the next uri based on base uri and location header fragment
|
||||
/// See <https://tools.ietf.org/html/rfc3986#section-4.2>
|
||||
|
|
|
@ -76,8 +76,10 @@ fn validate_no_file_from_remote(
|
|||
match specifier_url.scheme() {
|
||||
"http" | "https" => {}
|
||||
_ => {
|
||||
let e = ErrBox::new("PermissionDenied",
|
||||
"Remote modules are not allowed to statically import local modules. Use dynamic import instead.".to_string()
|
||||
let e = ErrBox::new(
|
||||
"PermissionDenied",
|
||||
"Remote modules are not allowed to statically import local \
|
||||
modules. Use dynamic import instead.",
|
||||
);
|
||||
return Err(err_with_location(e, maybe_location));
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ fn test_error_record() {
|
|||
arg: -1,
|
||||
error_len: 11,
|
||||
error_class: b"BadResource",
|
||||
error_message: "Error".to_string().as_bytes().to_owned(),
|
||||
error_message: b"Error".to_vec(),
|
||||
};
|
||||
let buf: Buf = err_record.into();
|
||||
assert_eq!(buf, expected.into_boxed_slice());
|
||||
|
|
|
@ -199,9 +199,7 @@ fn op_seek(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
let pos = std_file_resource(&mut resource_table, rid, |r| match r {
|
||||
Ok(std_file) => std_file.seek(seek_from).map_err(ErrBox::from),
|
||||
Err(_) => Err(ErrBox::type_error(
|
||||
"cannot seek on this type of resource".to_string(),
|
||||
)),
|
||||
Err(_) => Err(ErrBox::type_error("cannot seek on this type of resource")),
|
||||
})?;
|
||||
Ok(JsonOp::Sync(json!(pos)))
|
||||
} else {
|
||||
|
@ -211,9 +209,9 @@ fn op_seek(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
let pos = std_file_resource(&mut resource_table, rid, |r| match r {
|
||||
Ok(std_file) => std_file.seek(seek_from).map_err(ErrBox::from),
|
||||
Err(_) => Err(ErrBox::type_error(
|
||||
"cannot seek on this type of resource".to_string(),
|
||||
)),
|
||||
Err(_) => {
|
||||
Err(ErrBox::type_error("cannot seek on this type of resource"))
|
||||
}
|
||||
})?;
|
||||
Ok(json!(pos))
|
||||
};
|
||||
|
@ -245,9 +243,7 @@ fn op_fdatasync(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
std_file_resource(&mut resource_table, 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(),
|
||||
)),
|
||||
Err(_) => Err(ErrBox::type_error("cannot sync this type of resource")),
|
||||
})?;
|
||||
Ok(JsonOp::Sync(json!({})))
|
||||
} else {
|
||||
|
@ -255,9 +251,7 @@ fn op_fdatasync(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
std_file_resource(&mut resource_table, 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(),
|
||||
)),
|
||||
Err(_) => Err(ErrBox::type_error("cannot sync this type of resource")),
|
||||
})?;
|
||||
Ok(json!({}))
|
||||
};
|
||||
|
@ -289,9 +283,7 @@ fn op_fsync(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
std_file_resource(&mut resource_table, 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(),
|
||||
)),
|
||||
Err(_) => Err(ErrBox::type_error("cannot sync this type of resource")),
|
||||
})?;
|
||||
Ok(JsonOp::Sync(json!({})))
|
||||
} else {
|
||||
|
@ -299,9 +291,7 @@ fn op_fsync(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
std_file_resource(&mut resource_table, 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(),
|
||||
)),
|
||||
Err(_) => Err(ErrBox::type_error("cannot sync this type of resource")),
|
||||
})?;
|
||||
Ok(json!({}))
|
||||
};
|
||||
|
@ -333,9 +323,7 @@ fn op_fstat(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
let metadata = std_file_resource(&mut resource_table, 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(),
|
||||
)),
|
||||
Err(_) => Err(ErrBox::type_error("cannot stat this type of resource")),
|
||||
})?;
|
||||
Ok(JsonOp::Sync(get_stat_json(metadata).unwrap()))
|
||||
} else {
|
||||
|
@ -344,9 +332,9 @@ fn op_fstat(
|
|||
let metadata =
|
||||
std_file_resource(&mut resource_table, 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(),
|
||||
)),
|
||||
Err(_) => {
|
||||
Err(ErrBox::type_error("cannot stat this type of resource"))
|
||||
}
|
||||
})?;
|
||||
Ok(get_stat_json(metadata).unwrap())
|
||||
};
|
||||
|
@ -879,7 +867,7 @@ fn op_symlink(
|
|||
Some(options) => match options._type.as_ref() {
|
||||
"file" => symlink_file(&oldpath, &newpath)?,
|
||||
"dir" => symlink_dir(&oldpath, &newpath)?,
|
||||
_ => return Err(ErrBox::type_error("unsupported type".to_string())),
|
||||
_ => return Err(ErrBox::type_error("unsupported type")),
|
||||
},
|
||||
None => {
|
||||
let old_meta = std::fs::metadata(&oldpath);
|
||||
|
@ -955,9 +943,9 @@ fn op_ftruncate(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
std_file_resource(&mut resource_table, 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".to_string(),
|
||||
)),
|
||||
Err(_) => {
|
||||
Err(ErrBox::type_error("cannot truncate this type of resource"))
|
||||
}
|
||||
})?;
|
||||
Ok(JsonOp::Sync(json!({})))
|
||||
} else {
|
||||
|
@ -965,9 +953,9 @@ fn op_ftruncate(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
std_file_resource(&mut resource_table, 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".to_string(),
|
||||
)),
|
||||
Err(_) => {
|
||||
Err(ErrBox::type_error("cannot truncate this type of resource"))
|
||||
}
|
||||
})?;
|
||||
Ok(json!({}))
|
||||
};
|
||||
|
|
|
@ -117,7 +117,7 @@ fn get_stdio_stream(
|
|||
}
|
||||
|
||||
fn no_buffer_specified() -> ErrBox {
|
||||
ErrBox::type_error("no buffer specified".to_string())
|
||||
ErrBox::type_error("no buffer specified")
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
@ -262,9 +262,9 @@ pub fn op_read(
|
|||
.map(|n: usize| n as i32)
|
||||
.map_err(ErrBox::from)
|
||||
}
|
||||
Err(_) => Err(ErrBox::type_error(
|
||||
"sync read not allowed on this resource".to_string(),
|
||||
)),
|
||||
Err(_) => {
|
||||
Err(ErrBox::type_error("sync read not allowed on this resource"))
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
|
@ -383,9 +383,9 @@ pub fn op_write(
|
|||
.map(|nwritten: usize| nwritten as i32)
|
||||
.map_err(ErrBox::from)
|
||||
}
|
||||
Err(_) => Err(ErrBox::type_error(
|
||||
"sync read not allowed on this resource".to_string(),
|
||||
)),
|
||||
Err(_) => {
|
||||
Err(ErrBox::type_error("sync read not allowed on this resource"))
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -53,9 +53,7 @@ fn accept_tcp(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
let listener_resource = resource_table
|
||||
.get_mut::<TcpListenerResource>(rid)
|
||||
.ok_or_else(|| {
|
||||
ErrBox::bad_resource("Listener has been closed".to_string())
|
||||
})?;
|
||||
.ok_or_else(|| ErrBox::bad_resource("Listener has been closed"))?;
|
||||
let listener = &mut listener_resource.listener;
|
||||
match listener.poll_accept(cx).map_err(ErrBox::from) {
|
||||
Poll::Ready(Ok((stream, addr))) => {
|
||||
|
@ -142,9 +140,7 @@ fn receive_udp(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
let resource = resource_table
|
||||
.get_mut::<UdpSocketResource>(rid)
|
||||
.ok_or_else(|| {
|
||||
ErrBox::bad_resource("Socket has been closed".to_string())
|
||||
})?;
|
||||
.ok_or_else(|| ErrBox::bad_resource("Socket has been closed"))?;
|
||||
let socket = &mut resource.socket;
|
||||
socket
|
||||
.poll_recv_from(cx, &mut zero_copy)
|
||||
|
@ -216,9 +212,7 @@ fn op_datagram_send(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
let resource = resource_table
|
||||
.get_mut::<UdpSocketResource>(rid as u32)
|
||||
.ok_or_else(|| {
|
||||
ErrBox::bad_resource("Socket has been closed".to_string())
|
||||
})?;
|
||||
.ok_or_else(|| ErrBox::bad_resource("Socket has been closed"))?;
|
||||
resource
|
||||
.socket
|
||||
.poll_send_to(cx, &zero_copy, &addr)
|
||||
|
|
|
@ -43,9 +43,7 @@ pub fn accept_unix(
|
|||
let listener_resource = {
|
||||
resource_table_
|
||||
.get_mut::<UnixListenerResource>(rid)
|
||||
.ok_or_else(|| {
|
||||
ErrBox::bad_resource("Listener has been closed".to_string())
|
||||
})?
|
||||
.ok_or_else(|| ErrBox::bad_resource("Listener has been closed"))?
|
||||
};
|
||||
|
||||
let (unix_stream, _socket_addr) =
|
||||
|
@ -90,9 +88,7 @@ pub fn receive_unix_packet(
|
|||
let mut resource_table_ = resource_table.borrow_mut();
|
||||
let resource = resource_table_
|
||||
.get_mut::<UnixDatagramResource>(rid)
|
||||
.ok_or_else(|| {
|
||||
ErrBox::bad_resource("Socket has been closed".to_string())
|
||||
})?;
|
||||
.ok_or_else(|| ErrBox::bad_resource("Socket has been closed"))?;
|
||||
let (size, remote_addr) = resource.socket.recv_from(&mut zero_copy).await?;
|
||||
Ok(json!({
|
||||
"size": size,
|
||||
|
|
|
@ -371,9 +371,7 @@ fn op_accept_tls(
|
|||
let mut resource_table = resource_table.borrow_mut();
|
||||
let listener_resource = resource_table
|
||||
.get_mut::<TlsListenerResource>(rid)
|
||||
.ok_or_else(|| {
|
||||
ErrBox::bad_resource("Listener has been closed".to_string())
|
||||
})?;
|
||||
.ok_or_else(|| ErrBox::bad_resource("Listener has been closed"))?;
|
||||
let listener = &mut listener_resource.listener;
|
||||
match listener.poll_accept(cx).map_err(ErrBox::from) {
|
||||
Poll::Ready(Ok((stream, addr))) => {
|
||||
|
|
|
@ -49,7 +49,7 @@ pub fn kill(pid: i32, signal: i32) -> Result<(), ErrBox> {
|
|||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(ErrBox::type_error("unsupported signal".to_string()));
|
||||
return Err(ErrBox::type_error("unsupported signal"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -450,7 +450,7 @@ impl fmt::Debug for ErrWithV8Handle {
|
|||
mod tests {
|
||||
#[test]
|
||||
fn test_bad_resource() {
|
||||
let err = ErrBox::bad_resource("Resource has been closed".to_string());
|
||||
let err = ErrBox::bad_resource("Resource has been closed");
|
||||
assert_eq!(err.1, "BadResource");
|
||||
assert_eq!(err.to_string(), "Resource has been closed");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue