8000 Route codegen error includes literal escape codes · Issue #2901 · rwf2/Rocket · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Route codegen error includes literal escape codes #2901
Open
@robjwells

Description

@robjwells

Rocket Version

0.5.1

Operating System

macOS 12.7.6

Rust Toolchain Version

rustc 1.84.0 (9fc6b4312 2025-01-07)

What happened?

When encountering an (expected) error in route codegen with a mismatched path variable and function argument, the compiler error mesage includes terminal color escape codes as literal text, making the error message difficult to read.

Test Case

use rocket::{get, routes};

#[get("/hello/<name>")]
fn hello(other: &str) -> String {
    format!("Hello, {other}!")
}

#[rocket::launch]
fn rocket() -> rocket::Rocket<rocket::Build> {
    rocket::build().mount("/", routes![hello])
}

Log Output

❯ ROCKET_LOG_LEVEL=debug cargo build
   Compiling rocketroutetest v0.1.0 (/Users/robjwells/Desktop/rocketroutetest)
error: unused parameter
 --> src/main.rs:3:7
  |
3 | #[get("/hello/<name>")]
  |       ^^^^^^^^^^^^^^^

error: ␛[1;34m[␛[0m␛[1;32mnote␛[0m␛[1;34m] ␛[0m␛[1;39mexpected argument named `name` here␛[0m
 --> src/main.rs:4:9
  |
4 | fn hello(other: &str) -> String {
  |         ^^^^^^^^^^^^^

error[E0422]: cannot find struct, variant or union type `hello` in this scope
  --> src/main.rs:10:40
   |
10 |     rocket::build().mount("/", routes![hello])
   |                                        ^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0422`.
error: could not compile `rocketroutetest` (bin "rocketroutetest") due to 3 previous errors

Additional Context

The source of the message is here:

let msg = format!("expected argument named `{}` here", param.name);
let diag = param.span().error("unused parameter").span_note(args.span, msg);

This isn't affected by ROCKET_CLI_COLORS. There is no rocket.toml in the project. I don't have RUST_LOG or anything similar set in my shell env.

System Checks

  • My bug report relates to functionality.
  • I have tested against the latest Rocket release or a recent git commit.
  • I have tested against the latest stable rustc toolchain.
  • I was unable to find this issue previously reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstreamAn unresolvable issue: an upstream dependency bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0