summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-05-08 22:45:06 -0400
committerGitHub <noreply@github.com>2024-05-08 22:45:06 -0400
commit47f7bed677a6b72e873712de8f3988ea891710e4 (patch)
tree096549459b479cf1383e65c87b77e9f9482df258 /runtime
parente6dc4dfbff25e77d2127591802229b4a74037d24 (diff)
chore: enable clippy::print_stdout and clippy::print_stderr (#23732)
1. Generally we should prefer to use the `log` crate. 2. I very often accidentally commit `eprintln`s. When we should use `println` or `eprintln`, it's not too bad to be a bit more verbose and ignore the lint rule.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/examples/extension/main.rs3
-rw-r--r--runtime/inspector_server.rs18
-rw-r--r--runtime/permissions/prompter.rs3
-rw-r--r--runtime/snapshot.rs1
-rw-r--r--runtime/tokio_util.rs3
-rw-r--r--runtime/web_worker.rs2
-rw-r--r--runtime/worker.rs3
7 files changed, 22 insertions, 11 deletions
diff --git a/runtime/examples/extension/main.rs b/runtime/examples/extension/main.rs
index 0026d0de0..0d7c4efb0 100644
--- a/runtime/examples/extension/main.rs
+++ b/runtime/examples/extension/main.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
+
use std::path::Path;
use std::rc::Rc;
diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs
index 8d93819e9..48d8e0a8f 100644
--- a/runtime/inspector_server.rs
+++ b/runtime/inspector_server.rs
@@ -176,7 +176,7 @@ fn handle_ws_request(
let websocket = match fut.await {
Ok(w) => w,
Err(err) => {
- eprintln!(
+ log::error!(
"Inspector server failed to upgrade to WS connection: {:?}",
err
);
@@ -194,7 +194,7 @@ fn handle_ws_request(
rx: inbound_rx,
};
- eprintln!("Debugger session started.");
+ log::info!("Debugger session started.");
let _ = new_session_tx.unbounded_send(inspector_session_proxy);
pump_websocket_messages(websocket, inbound_tx, outbound_rx).await;
});
@@ -244,13 +244,13 @@ async fn server(
let inspector_map = Rc::clone(&inspector_map_);
let mut register_inspector_handler = pin!(register_inspector_rx
.map(|info| {
- eprintln!(
+ log::info!(
"Debugger listening on {}",
info.get_websocket_debugger_url(&info.host.to_string())
);
- eprintln!("Visit chrome://inspect to connect to the debugger.");
+ log::info!("Visit chrome://inspect to connect to the debugger.");
if info.wait_for_session {
- eprintln!("Deno is waiting for debugger to connect.");
+ log::info!("Deno is waiting for debugger to connect.");
}
if inspector_map.borrow_mut().insert(info.uuid, info).is_some() {
panic!("Inspector UUID already in map");
@@ -277,7 +277,7 @@ async fn server(
let listener = match TcpListener::from_std(listener) {
Ok(l) => l,
Err(err) => {
- eprintln!("Cannot start inspector server: {:?}", err);
+ log::error!("Cannot start inspector server: {:?}", err);
return;
}
};
@@ -293,7 +293,7 @@ async fn server(
match accept_result {
Ok((s, _)) => s,
Err(err) => {
- eprintln!("Failed to accept inspector connection: {:?}", err);
+ log::error!("Failed to accept inspector connection: {:?}", err);
continue;
}
}
@@ -356,7 +356,7 @@ async fn server(
tokio::select! {
result = conn.as_mut() => {
if let Err(err) = result {
- eprintln!("Failed to serve connection: {:?}", err);
+ log::error!("Failed to serve connection: {:?}", err);
}
},
_ = &mut shutdown_rx => {
@@ -409,7 +409,7 @@ async fn pump_websocket_messages(
OpCode::Close => {
// Users don't care if there was an error coming from debugger,
// just about the fact that debugger did disconnect.
- eprintln!("Debugger session ended");
+ log::info!("Debugger session ended");
break 'pump;
}
_ => {
diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs
index 42567b1e9..59a3a2f7b 100644
--- a/runtime/permissions/prompter.rs
+++ b/runtime/permissions/prompter.rs
@@ -280,6 +280,7 @@ impl PermissionPrompter for TtyPrompter {
return PromptResponse::Deny;
};
+ #[allow(clippy::print_stderr)]
if message.len() > MAX_PERMISSION_PROMPT_LENGTH {
eprintln!("❌ Permission prompt length ({} bytes) was larger than the configured maximum length ({} bytes): denying request.", message.len(), MAX_PERMISSION_PROMPT_LENGTH);
eprintln!("❌ WARNING: This may indicate that code is trying to bypass or hide permission check requests.");
@@ -298,6 +299,7 @@ impl PermissionPrompter for TtyPrompter {
// For security reasons we must consume everything in stdin so that previously
// buffered data cannot affect the prompt.
+ #[allow(clippy::print_stderr)]
if let Err(err) = clear_stdin(&mut stdin_lock, &mut stderr_lock) {
eprintln!("Error clearing stdin for permission prompt. {err:#}");
return PromptResponse::Deny; // don't grant permission if this fails
@@ -336,6 +338,7 @@ impl PermissionPrompter for TtyPrompter {
// Clear stdin each time we loop around in case the user accidentally pasted
// multiple lines or otherwise did something silly to generate a torrent of
// input. This doesn't work on Windows because `clear_stdin` has other side-effects.
+ #[allow(clippy::print_stderr)]
#[cfg(unix)]
if let Err(err) = clear_stdin(&mut stdin_lock, &mut stderr_lock) {
eprintln!("Error clearing stdin for permission prompt. {err:#}");
diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs
index 2a7d97641..923ea0b75 100644
--- a/runtime/snapshot.rs
+++ b/runtime/snapshot.rs
@@ -296,6 +296,7 @@ pub fn create_runtime_snapshot(
let mut snapshot = std::fs::File::create(snapshot_path).unwrap();
snapshot.write_all(&output.output).unwrap();
+ #[allow(clippy::print_stdout)]
for path in output.files_loaded_during_snapshot {
println!("cargo:rerun-if-changed={}", path.display());
}
diff --git a/runtime/tokio_util.rs b/runtime/tokio_util.rs
index da6e8b221..0d81f6e23 100644
--- a/runtime/tokio_util.rs
+++ b/runtime/tokio_util.rs
@@ -81,8 +81,9 @@ where
let handle = tokio::runtime::Handle::current();
let runtime_monitor = RuntimeMonitor::new(&handle);
tokio::spawn(async move {
+ #[allow(clippy::print_stderr)]
for interval in runtime_monitor.intervals() {
- println!("{:#?}", interval);
+ eprintln!("{:#?}", interval);
// wait 500ms
tokio::time::sleep(std::time::Duration::from_millis(
metrics_interval,
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index 27fe633ad..0124b12a3 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -805,6 +805,7 @@ impl WebWorker {
// TODO(mmastrac): we don't want to test this w/classic workers because
// WPT triggers a failure here. This is only exposed via --enable-testing-features-do-not-use.
+ #[allow(clippy::print_stderr)]
if self.worker_type == WebWorkerType::Module {
panic!(
"coding error: either js is polling or the worker is terminated"
@@ -878,6 +879,7 @@ impl WebWorker {
}
}
+#[allow(clippy::print_stderr)]
fn print_worker_error(
error: &AnyError,
name: &str,
diff --git a/runtime/worker.rs b/runtime/worker.rs
index ee6b256ff..a5fec16e4 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -279,6 +279,7 @@ pub fn create_op_metrics(
max_len.set(max_len.get().max(decl.name.len()));
let max_len = max_len.clone();
Some(Rc::new(
+ #[allow(clippy::print_stderr)]
move |op: &deno_core::_ops::OpCtx, event, source| {
eprintln!(
"[{: >10.3}] {name:max_len$}: {event:?} {source:?}",
@@ -518,7 +519,7 @@ impl MainWorker {
if !has_notified_of_inspector_disconnect
.swap(true, std::sync::atomic::Ordering::SeqCst)
{
- println!("Program finished. Waiting for inspector to disconnect to exit the process...");
+ log::info!("Program finished. Waiting for inspector to disconnect to exit the process...");
}
});