Skip to content

ServeDir::try_call does not propagate result as documented #412

Closed

Description

@Pistonight

Bug Report

Version

tower-http v0.4.4

Platform

All

Description

When using ServeDir::try_call to request a path that does not exist, it returns Ok(404) instead of an Err

use axum::http::Request;
use tower_http::services::ServeDir;
use tracing::{error, info};

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt::init();

    let mut serve_dir = ServeDir::new("src");

    let mut req = Request::new(());
    *req.uri_mut() = "/main.rs".parse().unwrap();
    match serve_dir.try_call(req).await {
        Ok(response) => info!("response code: {}", response.status()),
        Err(e) => error!("error: {}", e),
    }

    let mut req2 = Request::new(());
    *req2.uri_mut() = "/doesnotexist.rs".parse().unwrap();
    match serve_dir.try_call(req2).await {
        Ok(response) => info!("response code: {}", response.status()),
        Err(e) => error!("error: {}", e),
    }
}

Expected:

2023-09-23T18:09:09.141584Z  INFO rs_playground: response code: 200 OK
2023-09-23T18:09:09.141801Z  ERROR rs_playground: error: <something>

Actual:

2023-09-23T18:09:09.141584Z  INFO rs_playground: response code: 200 OK
2023-09-23T18:09:09.141801Z  INFO rs_playground: response code: 404 Not Found

Activity

  1. added
    C-bug
    on Nov 8, 2023
  2. jplatte commented on Nov 8, 2023

    @jplatte
    Contributor

    I think a PR to fix this would be welcome (cc @davidpdrsn).

  3. added a commit that references this issue on Aug 12, 2026
    8b9c6d6
  4. added a commit that references this issue on Aug 15, 2026
    90c072b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions