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

Workspace URI is not a file or directory

Error message

Workspace URI is not a file or directory: {uri:?}

What it means

An anyhow error raised while registering a workspace: the client-supplied URI is neither a file nor a directory URI scheme ty can map to a filesystem path (for example a non-file scheme). The workspace cannot be created from it.

Solutions

  1. Send workspace folders with file:// URIs
  2. Skip registration for URI schemes ty does not support
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at crates/ty_server/src/session.rs:1667

}

impl Workspaces {
    /// Registers a new workspace with the given URI and default settings for the workspace.
    ///
    /// This returns `true` when this workspace is added and `false`
    /// when it has already been added.
    ///
    /// It's the caller's responsibility to later call
    /// [`Session::request_uninitialized_workspace_folder_configurations`] with
    /// the resolved settings for this workspace. Registering and initializing
    /// a workspace is a two-step process because the workspace are announced
    /// to the server during the `initialize` request, but the resolved
    /// settings are only available after the client has responded to the
    /// `workspace/configuration` request.
    fn register(&mut self, uri: Uri) -> anyhow::Result<bool> {
        let path = uri
            .to_file_path()
            .map_err(|()| anyhow!("Workspace URI is not a file or directory: {uri:?}"))?;

        // Realistically I don't think this can fail because we got the path from a Uri
        let system_path = SystemPathBuf::from_path_buf(path)
            .map_err(|_| anyhow!("Workspace URI is not valid UTF8"))?;

        if self.workspaces.contains_key(&system_path) {
            return Ok(false);
        }

        self.workspaces.insert(
            system_path,
            Workspace {
                uri,
                settings: Arc::new(WorkspaceSettings::default()),
                initialized: false,
            },
        );
        Ok(true)

View on GitHub (pinned to 5bb508f594)