Improve the file watching failure error message#15728
Merged
Conversation
Member
Author
|
I looked at rendering the expected event, but.. it's a bit harder. |
Member
|
I'll leave this one to @MichaReiser 😆 |
MichaReiser
approved these changes
Jan 24, 2025
Member
MichaReiser
left a comment
There was a problem hiding this comment.
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![]));
Member
Author
|
That's pretty close to what I implemented! but I wasn't happy with |
Member
Most tests use the file name matcher. So it shouldn't be that big of a Problem |
Member
Author
|
Let's just ship this and consider that next :D |
dcreager
added a commit
that referenced
this pull request
Jan 27, 2025
* 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I really misunderstood this in #15664 (comment)