actix/actix-web · error · syn::Error

Multiple paths specified! There should be only one.

Error message

Multiple paths specified! There should be only one.

What it means

A method macro takes exactly one path. At actix-web-codegen/src/route.rs:44-48, after parsing the first path string and a comma, if the next token is another literal the macro reports a multi-path error rather than silently picking one. Options after the comma must be `key = value` pairs (`name`, `guard`, `wrap`, `method`), not a second path.

Source

Thrown at actix-web-codegen/src/route.rs:45

        })?;

        // verify that path pattern is valid
        let _ = ResourceDef::new(path.value());

        // if there's no comma, assume that no options are provided
        if !input.peek(Token![,]) {
            return Ok(Self {
                path,
                options: Punctuated::new(),
            });
        }

        // advance past comma separator
        input.parse::<Token![,]>()?;

        // if next char is a literal, assume that it is a string and show multi-path error
        if input.cursor().literal().is_some() {
            return Err(syn::Error::new(
                Span::call_site(),
                r#"Multiple paths specified! There should be only one."#,
            ));
        }

        // zero or more options: name = "foo"
        let options = input.parse_terminated(syn::MetaNameValue::parse, Token![,])?;

        Ok(Self { path, options })
    }
}

macro_rules! standard_method_type {
    (
        $($variant:ident, $upper:ident, $lower:ident,)+
    ) => {
        #[doc(hidden)]
        #[derive(Debug, Clone, PartialEq, Eq, Hash)]

View on GitHub (pinned to 937960ca67)

Solutions

  1. Keep only one path literal as the first argument.
  2. To register the same handler on multiple paths, use `#[routes]` with several method attributes, or register the route multiple times.

Example fix

// before
#[get("/foo", "/bar")]
async fn handler() -> HttpResponse { ... }

// after
#[get("/foo")]
async fn handler() -> HttpResponse { ... }

// or multiple paths via routes
#[routes]
#[get("/foo")]
#[get("/bar")]
async fn handler() -> HttpResponse { ... }
Defensive patterns

Strategy: validation

Validate before calling

// Compile-time only. A method macro accepts exactly one string-literal path;
// subsequent args must be key=value. Review each method attribute to ensure a single path.

Prevention

When it happens

Trigger: `#[get("/foo", "/bar")]` — supplying two string literals as if multiple paths were allowed.

Common situations: Misunderstanding the macro grammar and assuming a handler can register multiple paths in one attribute.

Related errors


AI-assisted analysis of actix/actix-web@937960ca67 (2026-08-06). Data as JSON: /data/errors/e537fbb876672e13.json. Report an issue: GitHub.