Repository: astral-sh/uv
File: crates/uv/src/commands/build_frontend.rs (Rust)

Code before:
        }
    }))
    .await;

    let mut success = true;
    for (source, result) in results {
        match result {
            Ok(messages) => {
                for message in messages {
                    message.print(printer)?;
                }
            }
            Err(err) => {
                let help = if let Error::Extract(uv_extract::Error::Tar(err)) = &err {
                    // TODO(konsti): astral-tokio-tar should use a proper error instead of
                    // encoding everything in strings
                    if err.to_string().contains("/bin/python")
                        && std::error::Error::source(err).is_some_and(|err| {
                            err.to_string().ends_with("outside of the target directory")
                        })
                    {
                        Some(
                            "This file seems to be part of a virtual environment. Virtual environments must be excluded from source distributions."
                                .to_string(),
                        )
                    } else {
                        None
                    }
                } else {
                    None
                };

                #[derive(Debug, miette::Diagnostic, thiserror::Error)]
                #[error("Failed to build `{source}`", source = source.cyan())]
                #[diagnostic()]
                struct Diagnostic {
                    source: String,
                    #[source]
                    cause: anyhow::Error,
                    #[help]
                    help: Option<String>,
                }

                let report = miette::Report::new(Diagnostic {
                    source: source.to_string(),
                    cause: err.into(),
                    help,
                });
                anstream::eprint!("{report:?}");

                success = false;

Review comment (suggestion):
The tokio-tar crate has an effectively stringly-types, very nested, everything-is-an-io::Error interface.

Code after:
        }
    }))
    .await;

    let mut success = true;
    for (source, result) in results {
        match result {
            Ok(messages) => {
                for message in messages {
                    message.print(printer)?;
                }
            }
            Err(err) => {
                #[derive(Debug, miette::Diagnostic, thiserror::Error)]
                #[error("Failed to build `{source}`", source = source.cyan())]
                #[diagnostic()]
                struct Diagnostic {
                    source: String,
                    #[source]
                    cause: anyhow::Error,
                    #[help]
                    help: Option<String>,
                }

                let help = if let Error::Extract(uv_extract::Error::Tar(err)) = &err {
                    // TODO(konsti): astral-tokio-tar should use a proper error instead of
                    // encoding everything in strings
                    if err.to_string().contains("/bin/python")
                        && std::error::Error::source(err).is_some_and(|err| {
                            err.to_string().ends_with("outside of the target directory")
                        })
                    {
                        Some(
                            "This file seems to be part of a virtual environment. Virtual environments must be excluded from source distributions."
                                .to_string(),
                        )
                    } else {
                        None
                    }
                } else {
                    None
                };

                let report = miette::Report::new(Diagnostic {
                    source: source.to_string(),
                    cause: err.into(),
                    help,
                });
                anstream::eprint!("{report:?}");

                success = false;