astral-sh/ruff · warning

Invalid command `{name}`

Error message

Invalid command `{name}`

What it means

The server parses incoming `workspace/executeCommand` names into a `Command` enum via `from_str`. Any command string other than the four supported ones (applyAutofix, applyFormat, applyOrganizeImports, printDebugInformation) produces this anyhow error, which surfaces as a request failure to the client.

Source

Thrown at crates/ruff_server/src/server.rs:368

        [
            SupportedCommand::Format,
            SupportedCommand::FixAll,
            SupportedCommand::OrganizeImports,
            SupportedCommand::Debug,
        ]
    }
}

impl FromStr for SupportedCommand {
    type Err = anyhow::Error;

    fn from_str(name: &str) -> anyhow::Result<Self, Self::Err> {
        Ok(match name {
            "ruff.applyAutofix" => Self::FixAll,
            "ruff.applyFormat" => Self::Format,
            "ruff.applyOrganizeImports" => Self::OrganizeImports,
            "ruff.printDebugInformation" => Self::Debug,
            _ => return Err(anyhow::anyhow!("Invalid command `{name}`")),
        })
    }
}

type PanicHook = Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>;

struct ServerPanicHookHandler {
    hook: Option<PanicHook>,
    // Hold on to the strong reference for as long as the panic hook is set.
    _client: Arc<Client>,
}

impl ServerPanicHookHandler {
    fn new(client: Client) -> Self {
        let hook = std::panic::take_hook();
        let client = Arc::new(client);

        // Use a weak reference to the client because it must be dropped when exiting or the

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Use one of the exact supported commands: ruff.applyAutofix, ruff.applyFormat, ruff.applyOrganizeImports, ruff.printDebugInformation
  2. Check the client/plugin version matches the Ruff server version and update both
  3. Inspect `client -> server` logs to confirm the exact command string casing
  4. If you need a new command, add it to the Command enum and its match arm in the server

Example fix

// before
executeCommand('ruff.applyFixAll')
// after
executeCommand('ruff.applyAutofix')
Defensive patterns

Strategy: validation

Validate before calling

// Client-side whitelist before executeCommand
const RUFF_COMMANDS = new Set([
  'ruff.applyAutofix', 'ruff.applyFormat',
  'ruff.applyOrganizeImports', 'ruff.printDebugInformation',
]);
if (!RUFF_COMMANDS.has(command)) throw new Error(`unsupported: ${command}`);

Try / catch

// TypeScript
try {
  await commands.executeCommand('ruff.applyAutofix');
} catch (e) {
  if (String(e.message).includes('Invalid command')) {
    console.warn('Command not supported by this Ruff server version');
  } else throw e;
}

Prevention

When it happens

Trigger: Client sends `workspace/executeCommand` with a name like `ruff.applyRuleFix`, a typo (`ruff.applyautoFix`), or a command registered by another extension but routed to Ruff.

Common situations: Editor integrations hardcoding command names from an older Ruff server version; users binding a keybinding to a renamed command; other language servers' commands invoked in a file where Ruff is the active server.

Related errors


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