CherryHQ/cherry-studio · error · Error
Invalid command: command cannot be empty
Error message
Invalid command: command cannot be empty
What it means
Thrown by validateCommand() after trimming the command string, when the trimmed result is empty. This distinguishes from the non-empty-string check (error 153): the input was technically a string but contained only whitespace characters (spaces, tabs, newlines). The trimmed command is the return value of validateCommand, so a whitespace-only command would produce an empty executable name.
Source
Thrown at src/main/ai/mcp/McpPackageService.ts:147
* Commands should be either:
* 1. Simple command names (e.g., "node", "python", "npx") - looked up in PATH
* 2. Absolute paths (e.g., "/usr/bin/node", "C:\\Program Files\\node\\node.exe")
* 3. Relative paths starting with ./ or .\ (relative to extractDir)
*
* Rejects commands containing path traversal sequences (..)
*
* @param command - The command to validate
* @returns The validated command
* @throws Error if command contains path traversal or is invalid
*/
export function validateCommand(command: string): string {
if (!command || typeof command !== 'string') {
throw new Error('Invalid command: command must be a non-empty string')
}
const trimmed = command.trim()
if (!trimmed) {
throw new Error('Invalid command: command cannot be empty')
}
// Check for path traversal sequences
// This catches: .., ../, ..\, /../, \..\, etc.
if (/(?:^|[/\\])\.\.(?:[/\\]|$)/.test(trimmed) || trimmed === '..') {
throw new Error(`Invalid command: path traversal detected in "${command}"`)
}
// Check for null bytes
if (trimmed.includes('\0')) {
throw new Error('Invalid command: null byte detected')
}
return trimmed
}
/**
* Validate command arguments to prevent injection attacks.View on GitHub (pinned to 726446b54c)
Solutions
- Set the manifest's command to a real executable name (e.g., 'node', 'python', 'npx', or an absolute path).
- If using variable substitution, verify the substitution source (user_config) provides a non-empty value.
- Validate the manifest with a schema that enforces minLength: 1 on the command field.
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate that command is not whitespace-only
if (typeof command === 'string' && command.trim().length === 0) {
throw new Error('Manifest command field cannot be whitespace-only')
} Type guard
function isNonEmptyTrimmedString(value: unknown): value is string {
return typeof value === 'string' && value.trim().length > 0
} Prevention
- Enforce minLength: 1 with a trim transform in the manifest schema validator.
- Test manifest command fields with whitespace-only values to confirm they are caught.
- When authoring manifests, use real executable names — never placeholders.
When it happens
Trigger: Called from resolveMcpConfig at line 351. Triggers when the manifest's command field is a string like ' ', '\t\n', or any combination of whitespace-only characters. After performVariableSubstitution, a command like '${user_config.executor}' that resolved to whitespace would also hit this.
Common situations: A manifest author left a placeholder command that was never filled in; variable substitution replaced a template with an empty/whitespace user-config value; copy-paste from a formatted document introduced stray whitespace.
Related errors
- Invalid command: command must be a non-empty string
- Invalid command: path traversal detected in "${command}"
- Invalid command: null byte detected
- Invalid args: must be an array
- Invalid args: argument at index ${index} must be a string
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/fbf6b7f9f2eb9ce1.
Report an issue: GitHub.