-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the file watching failure error message #15728
Conversation
I looked at rendering the expected event, but.. it's a bit harder. |
I'll leave this one to @MichaReiser 😆 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, you could do
Index: crates/red_knot/tests/file_watching.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/crates/red_knot/tests/file_watching.rs b/crates/red_knot/tests/file_watching.rs
--- a/crates/red_knot/tests/file_watching.rs (revision 26f7e46dc8348ba17ba6db1a61e7c296e7906428)
+++ b/crates/red_knot/tests/file_watching.rs (date 1737743417656)
@@ -1,5 +1,8 @@
#![allow(clippy::disallowed_names)]
+use core::fmt;
+use std::fmt::Display;
use std::io::Write;
use std::time::{Duration, Instant};
@@ -39,15 +42,18 @@
}
#[track_caller]
- fn stop_watch<M>(&mut self, matcher: M) -> Vec<ChangeEvent>
+ fn stop_watch<M>(&mut self, mut matcher: M) -> Vec<ChangeEvent>
where
M: MatchEvent,
{
// track_caller is unstable for lambdas -> That's why this is a fn
#[track_caller]
- fn panic_with_formatted_events(events: Vec<ChangeEvent>) -> Vec<ChangeEvent> {
+ fn panic_with_formatted_events(
+ expected: &str,
+ events: Vec<ChangeEvent>,
+ ) -> Vec<ChangeEvent> {
panic!(
- "Didn't observe expected change:\n{}",
+ "Didn't observe expected change: `{expected}`\n{}",
events
.into_iter()
.map(|event| format!(" - {event:?}"))
@@ -56,13 +62,15 @@
)
}
- self.try_stop_watch(matcher, Duration::from_secs(10))
- .unwrap_or_else(panic_with_formatted_events)
+ self.try_stop_watch(&mut matcher, Duration::from_secs(10))
+ .unwrap_or_else(|events| {
+ panic_with_formatted_events(&matcher.display().to_string(), events)
+ })
}
fn try_stop_watch<M>(
&mut self,
- mut matcher: M,
+ matcher: &mut M,
timeout: Duration,
) -> Result<Vec<ChangeEvent>, Vec<ChangeEvent>>
where
@@ -204,10 +212,26 @@
trait MatchEvent {
fn match_event(&mut self, event: &ChangeEvent) -> bool;
+
+ fn display(&self) -> impl fmt::Display;
}
fn event_for_file(name: &str) -> impl MatchEvent + '_ {
- |event: &ChangeEvent| event.file_name() == Some(name)
+ MatchFile { name }
+}
+
+struct MatchFile<'a> {
+ name: &'a str,
+}
+
+impl MatchEvent for MatchFile<'_> {
+ fn match_event(&mut self, event: &ChangeEvent) -> bool {
+ event.file_name() == Some(self.name)
+ }
+
+ fn display(&self) -> impl Display {
+ format!("file name == {name}", name = self.name)
+ }
}
impl<F> MatchEvent for F
@@ -217,6 +241,10 @@
fn match_event(&mut self, event: &ChangeEvent) -> bool {
(*self)(event)
}
+
+ fn display(&self) -> impl Display {
+ "<func>"
+ }
}
trait SetupFiles {
@@ -874,7 +902,7 @@
std::fs::write(site_packages.join("a.py").as_std_path(), "class A: ...")?;
- let changes = case.try_stop_watch(|_: &ChangeEvent| true, Duration::from_millis(100));
+ let changes = case.try_stop_watch(&mut |_: &ChangeEvent| true, Duration::from_millis(100));
assert_eq!(changes, Err(vec![]));
That's pretty close to what I implemented! but I wasn't happy with |
Most tests use the file name matcher. So it shouldn't be that big of a Problem |
Let's just ship this and consider that next :D |
* main: Run `cargo update` (#15769) [red-knot] Document public symbol type inferece (#15766) Update dawidd6/action-download-artifact action to v8 (#15760) Update NPM Development dependencies (#15758) Update pre-commit dependencies (#15756) Update dependency ruff to v0.9.3 (#15755) Update dependency mdformat-mkdocs to v4.1.2 (#15754) Update Rust crate uuid to v1.12.1 (#15753) Update Rust crate unicode-ident to v1.0.15 (#15752) Fix docstring in ruff_annotate_snippets (#15748) Update Rust crate insta to v1.42.1 (#15751) Update Rust crate clap to v4.5.27 (#15750) Add references to `trio.run_process` and `anyio.run_process` (#15761) [`ruff`] Do not emit diagnostic when all arguments to `zip()` are variadic (`RUF058`) (#15744) [red-knot] Ensure differently ordered unions are considered equivalent when they appear inside tuples inside top-level intersections (#15743) [red-knot] Ensure differently ordered unions and intersections are understood as equivalent even inside arbitrarily nested tuples (#15740) [red-knot] Promote the `all_type_pairs_are_assignable_to_their_union` property test to stable (#15739) [`pylint`] Do not trigger `PLR6201` on empty collections (#15732) Improve the file watching failure error message (#15728) Speed symbol state merging back up (#15731)
I really misunderstood this in #15664 (comment)