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

Code before:
            // If the user ran `uvx run ...`, the `run` is likely a mistake. Show a dedicated hint.
            if from.is_none() && invocation_source == ToolRunCommand::Uvx && target == "run" {
                let rest = args.iter().map(|s| s.to_string_lossy()).join(" ");
                return diagnostics::OperationDiagnostic::native_tls(
                    client_builder.is_native_tls(),
                )
                .with_hint(format!(
                    "`{}` invokes the `{}` package. Did you mean `{}`?",
                    format!("uvx run {rest}").green(),
                    "run".cyan(),
                    format!("uvx {rest}").green()
                ))
                .with_context("tool")
                .report(err)
                .map_or(Ok(ExitStatus::Failure), |err| Err(err.into()));
            }

            let diagnostic =
                diagnostics::OperationDiagnostic::native_tls(client_builder.is_native_tls());
            let diagnostic = if let Some(verbose_flag) = find_verbose_flag(args) {
                diagnostic.with_hint(format!(
                    "You provided `{}` to `{}`. Did you mean to provide it to `{}`? e.g., `{}`",
                    verbose_flag.cyan(),
                    target.cyan(),
                    invocation_source.to_string().cyan(),
                    format!("{invocation_source} {verbose_flag} {target}").green()
                ))
            } else {
                diagnostic.with_context("tool")
            };
            return diagnostic
                .report(err)
                .map_or(Ok(ExitStatus::Failure), |err| Err(err.into()));
        }

        Err(ProjectError::Requirements(err)) => {
            let err = miette::Report::msg(format!("{err}"))
                .context("Failed to resolve `--with` requirement");
            eprint!("{err:?}");
            return Ok(ExitStatus::Failure);
        }
        Err(err) => return Err(err.into()),
    };

    // TODO(zanieb): Determine the executable command via the package entry points
    let executable = from.executable();
    let site_packages = SitePackages::from_environment(&environment)?;

    // Check if the provided command is not part of the executables for the `from` package,
    // and if it's provided by another package in the environment.
    let provider_hints = match &from {

Review comment (suggestion):
I think that the verbose hint shouldn't change how the rest of the error looks. So it would be good if it also called `.with_context("tool")`. But it looks like it's easier said than done as the relevant code doesn't support it at the moment: https://github.com/astral-sh/uv/blob/5a6f2ea319b0d7b6ffaf5b61e1de6c9060282c08/crates/uv/src/commands/diagnostics.rs#L77

It also seems like some of the other error cases drop the hint entirely.

Code after:
            if from.is_none() && invocation_source == ToolRunCommand::Uvx && target == "run" {
                let rest = args.iter().map(|s| s.to_string_lossy()).join(" ");
                return diagnostics::OperationDiagnostic::native_tls(
                    client_builder.is_native_tls(),
                )
                .with_hint(format!(
                    "`{}` invokes the `{}` package. Did you mean `{}`?",
                    format!("uvx run {rest}").green(),
                    "run".cyan(),
                    format!("uvx {rest}").green()
                ))
                .with_context("tool")
                .report(err)
                .map_or(Ok(ExitStatus::Failure), |err| Err(err.into()));
            }

            let diagnostic =
                diagnostics::OperationDiagnostic::native_tls(client_builder.is_native_tls());
            let diagnostic = if let Some(verbose_flag) = find_verbose_flag(args) {
                diagnostic.with_hint(format!(
                    "You provided `{}` to `{}`. Did you mean to provide it to `{}`? e.g., `{}`",
                    verbose_flag.cyan(),
                    target.cyan(),
                    invocation_source.to_string().cyan(),
                    format!("{invocation_source} {verbose_flag} {target}").green()
                ))
            } else {
                diagnostic.with_context("tool")
            };
            return diagnostic
                .report(err)
                .map_or(Ok(ExitStatus::Failure), |err| Err(err.into()));
        }

        Err(ProjectError::Requirements(err)) => {
            let err = miette::Report::msg(format!("{err}"))
                .context("Failed to resolve `--with` requirement");
            eprint!("{err:?}");
            return Ok(ExitStatus::Failure);
        }
        Err(err) => return Err(err.into()),
    };

    // TODO(zanieb): Determine the executable command via the package entry points
    let executable = from.executable();
    let site_packages = SitePackages::from_environment(&environment)?;

    // Check if the provided command is not part of the executables for the `from` package,
    // and if it's provided by another package in the environment.
    let provider_hints = match &from {
        ToolRequirement::Python { .. } => None,