astral-sh/ruff · error
InvalidParams
InvalidParams
Error message
Invalid command `{name}` What it means
The Ruff language server accepts exactly four workspace/executeCommand command IDs: ruff.applyAutofix, ruff.applyFormat, ruff.applyOrganizeImports, and ruff.printDebugInformation. The command string from the request is parsed via FromStr; anything else fails to parse and the request is rejected with an InvalidParams error.
Solutions
- Use one of the exact IDs: ruff.applyAutofix, ruff.applyFormat, ruff.applyOrganizeImports, ruff.printDebugInformation
- Update the Ruff extension and server together so command names match the running version
- Check the server's tracing log to see the raw command string it received
- Prefer LSP native requests (textDocument/formatting, codeAction source.fixAll) over executeCommand where available
Example fix
// before
await connection.sendRequest('workspace/executeCommand', { command: 'ruff.applyFix', arguments: [{ uri: docUri }] });
// Error: Invalid command `ruff.applyFix`
// after
await connection.sendRequest('workspace/executeCommand', { command: 'ruff.applyAutofix', arguments: [{ uri: docUri }] }); Defensive patterns
Strategy: validation
Validate before calling
// Whitelist the commands this server version supports before invoking
const SUPPORTED = new Set([
'ruff.applyAutofix',
'ruff.applyFormat',
'ruff.applyOrganizeImports',
'ruff.printDebugInformation',
]);
if (!SUPPORTED.has(command)) throw new Error(`unsupported command: ${command}`);
await conn.sendRequest('workspace/executeCommand', { command, arguments }); Type guard
function isSupportedRuffCommand(cmd: string): cmd is
| 'ruff.applyAutofix' | 'ruff.applyFormat'
| 'ruff.applyOrganizeImports' | 'ruff.printDebugInformation' {
return cmd === 'ruff.applyAutofix' || cmd === 'ruff.applyFormat'
|| cmd === 'ruff.applyOrganizeImports' || cmd === 'ruff.printDebugInformation';
} Prevention
- Source the command list from the extension/server version in use rather than hardcoding
- Update extension and server together so command IDs stay in sync
- Prefer native LSP requests (formatting, codeAction) over executeCommand where possible
When it happens
Trigger: Typos like `ruff.applyFix` or `ruff.autofix`; invoking commands from a newer/older extension than the running server; clients guessing command names instead of using the ones the extension advertises; wrappers forwarding commands meant for another server.
Common situations: Custom editor integrations hardcoding command IDs across Ruff versions; mismatched extension/server versions after an upgrade; copy-pasted sample code using renamed commands.
Related errors
- Failed to send notification
- Failed to send response for request
- InternalError
- InternalError
- InternalError
AI-assisted analysis of astral-sh/ruff@d1087a4b9e (2026-08-20).
Data as JSON: /api/errors/1ffb4e3e14108265.
Report an issue: GitHub.
Appendix: 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 theView on GitHub (pinned to d1087a4b9e)