astral-sh/ruff · error · anyhow::Error

Failed to get the current working directory while creating…

Error message

Failed to get the current working directory while creating a default workspace.

What it means

An anyhow error raised while constructing a default workspace during server initialization: the client provided no workspace folders, and the fallback attempt to read the current working directory from the system failed. The server cannot determine a root to check files against.

Solutions

  1. Ensure the editor sends at least one workspace folder during initialize
  2. Run the server from a directory that can be resolved as a path
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/ty_server/src/server.rs:154 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/c0b02190c2fbafdd. Report an issue: GitHub.

Appendix: source

Thrown at crates/ty_server/src/server.rs:154

                    .map(|folder| folder.uri)
                    .collect::<Vec<_>>()
            })
            .or_else(|| {
                let current_dir = native_system
                    .current_directory()
                    .as_std_path()
                    .to_path_buf();
                tracing::warn!(
                    "No workspace(s) were provided during initialization. \
                    Using the current working directory from the fallback system as a \
                    default workspace: {}",
                    current_dir.display()
                );
                let uri = Uri::from_file_path(current_dir).ok()?;
                Some(vec![uri])
            })
            .ok_or_else(|| {
                anyhow::anyhow!(
                    "Failed to get the current working directory while creating a \
                    default workspace."
                )
            })?;

        Ok(Self {
            connection,
            worker_threads,
            main_loop_receiver,
            main_loop_sender,
            session: Session::new(
                resolved_client_capabilities,
                position_encoding,
                workspace_urls,
                initialization_options,
                native_system,
                ClientName::from(client_info),
                in_test,

View on GitHub (pinned to 26f38c119c)