Open
Description
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:
Rocket/core/codegen/src/attribute/route/parse.rs
Lines 118 to 119 in f53611f
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.