[PATCH v2 2/2] rust: emit path candidates in panic message

Tamir Duberstein posted 2 patches 6 months, 3 weeks ago
[PATCH v2 2/2] rust: emit path candidates in panic message
Posted by Tamir Duberstein 6 months, 3 weeks ago
Include all information in the panic message rather than emit fragments
to stderr.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 scripts/rustdoc_test_gen.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs
index d796481f4359..f95129b03cd8 100644
--- a/scripts/rustdoc_test_gen.rs
+++ b/scripts/rustdoc_test_gen.rs
@@ -92,13 +92,15 @@ fn find_candidates(
         ),
         [valid_path] => valid_path.to_str().unwrap(),
         valid_paths => {
-            eprintln!("Several path candidates found:");
+            use std::fmt::Write;
+
+            let mut candidates = String::new();
             for path in valid_paths {
-                eprintln!("    {path:?}");
+                write!(&mut candidates, "    {path:?}").unwrap();
             }
             panic!(
                 "Several path candidates found for `{file}`, please resolve the ambiguity by \
-                renaming a file or folder."
+                renaming a file or folder. Candidates:\n{candidates}",
             );
         }
     }

-- 
2.49.0
Re: [PATCH v2 2/2] rust: emit path candidates in panic message
Posted by Miguel Ojeda 4 months, 4 weeks ago
On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> +                write!(&mut candidates, "    {path:?}").unwrap();

I assume this was supposed to be `writeln!`; otherwise, we lose the
newlines and the indent does not make much sense.

I will fix it when applying.

Cheers,
Miguel
Re: [PATCH v2 2/2] rust: emit path candidates in panic message
Posted by Tamir Duberstein 4 months, 4 weeks ago
On Sun, Jul 20, 2025 at 6:20 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > +                write!(&mut candidates, "    {path:?}").unwrap();
>
> I assume this was supposed to be `writeln!`; otherwise, we lose the
> newlines and the indent does not make much sense.

Duh, yes, that's right.

> I will fix it when applying.

Thank you!
Re: [PATCH v2 2/2] rust: emit path candidates in panic message
Posted by Miguel Ojeda 6 months, 3 weeks ago
On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> Include all information in the panic message rather than emit fragments
> to stderr.

Could we explain the "why" as well in the message? (i.e. not just the "what")

Thanks!

Cheers,
Miguel
Re: [PATCH v2 2/2] rust: emit path candidates in panic message
Posted by Tamir Duberstein 6 months, 2 weeks ago
On Thu, May 29, 2025 at 9:21 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, May 29, 2025 at 3:15 PM Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > Include all information in the panic message rather than emit fragments
> > to stderr.
>
> Could we explain the "why" as well in the message? (i.e. not just the "what")

Sure, that would be:

Include all information in the panic message rather than emit fragments
to stderr to avoid possible interleaving with other output.

Let me know if I should send another spin for this, or if this is ok
to do on apply.
Re: [PATCH v2 2/2] rust: emit path candidates in panic message
Posted by Miguel Ojeda 6 months, 2 weeks ago
On Thu, May 29, 2025 at 4:38 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> Sure, that would be:
>
> Include all information in the panic message rather than emit fragments
> to stderr to avoid possible interleaving with other output.
>
> Let me know if I should send another spin for this, or if this is ok
> to do on apply.

Thanks! No worries, I can do that on apply.

Cheers,
Miguel