diff --git a/cli/http_util.rs b/cli/http_util.rs index bf302f7b22..72aaee6827 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -44,12 +44,9 @@ pub fn create_http_client(ca_file: Option<&str>) -> Result { 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 diff --git a/cli/module_graph.rs b/cli/module_graph.rs index 7cbd4cfcc7..f7cfe42266 100644 --- a/cli/module_graph.rs +++ b/cli/module_graph.rs @@ -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)); } diff --git a/cli/ops/dispatch_minimal.rs b/cli/ops/dispatch_minimal.rs index b0dc7ad8a0..20e8160fff 100644 --- a/cli/ops/dispatch_minimal.rs +++ b/cli/ops/dispatch_minimal.rs @@ -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()); diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index 00736b813c..28b2a7e55c 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -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!({})) }; diff --git a/cli/ops/io.rs b/cli/ops/io.rs index 6b97f542cf..14d32a39b7 100644 --- a/cli/ops/io.rs +++ b/cli/ops/io.rs @@ -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 { diff --git a/cli/ops/net.rs b/cli/ops/net.rs index 25639cb79b..d979f44aef 100644 --- a/cli/ops/net.rs +++ b/cli/ops/net.rs @@ -53,9 +53,7 @@ fn accept_tcp( let mut resource_table = resource_table.borrow_mut(); let listener_resource = resource_table .get_mut::(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::(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::(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) diff --git a/cli/ops/net_unix.rs b/cli/ops/net_unix.rs index d8f6c67361..e03a7ba87e 100644 --- a/cli/ops/net_unix.rs +++ b/cli/ops/net_unix.rs @@ -43,9 +43,7 @@ pub fn accept_unix( let listener_resource = { resource_table_ .get_mut::(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::(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, diff --git a/cli/ops/tls.rs b/cli/ops/tls.rs index 97dca9d90b..2d47d8ebee 100644 --- a/cli/ops/tls.rs +++ b/cli/ops/tls.rs @@ -371,9 +371,7 @@ fn op_accept_tls( let mut resource_table = resource_table.borrow_mut(); let listener_resource = resource_table .get_mut::(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))) => { diff --git a/cli/signal.rs b/cli/signal.rs index fcc70d00ef..5c9a7d717a 100644 --- a/cli/signal.rs +++ b/cli/signal.rs @@ -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(()) diff --git a/core/errors.rs b/core/errors.rs index 3dfe5824c9..8fdcca0597 100644 --- a/core/errors.rs +++ b/core/errors.rs @@ -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"); }