CherryHQ/cherry-studio · error · Error
Invalid MCP package upload: file name cannot be empty
Error message
Invalid MCP package upload: file name cannot be empty
What it means
Thrown by validatePackageUploadPayload when fileName.trim() is the empty string. The filename is checked after the typeof guard, so this means a real string consisting only of whitespace (or the empty string) was supplied. An empty filename cannot be used to build a safe temp-file path and indicates the upload payload was malformed.
Source
Thrown at src/main/ai/mcp/McpPackageService.ts:288
resolvedEnv[key] = substituted
}
return resolvedEnv
}
export function validatePackageUploadPayload(
fileBuffer: ArrayBuffer | NodeJS.ArrayBufferView,
fileName: string,
packageFormat: McpPackageFormat
): Buffer {
if (typeof fileName !== 'string') {
throw new Error('Invalid MCP package upload: file name must be a string')
}
const trimmedFileName = fileName.trim()
if (!trimmedFileName) {
throw new Error('Invalid MCP package upload: file name cannot be empty')
}
if (trimmedFileName !== fileName) {
throw new Error('Invalid MCP package upload: file name cannot contain leading or trailing whitespace')
}
if (trimmedFileName.includes('\0') || /[/\\]/.test(trimmedFileName)) {
throw new Error('Invalid MCP package upload: file name cannot contain path separators')
}
if (!/^[A-Za-z0-9._ ()@+-]+$/.test(trimmedFileName)) {
throw new Error('Invalid MCP package upload: file name contains unsupported characters')
}
if (path.extname(trimmedFileName).toLowerCase() !== `.${packageFormat}`) {
throw new Error(`Invalid MCP package upload: expected a .${packageFormat} file`)
}
let buffer: Buffer
if (fileBuffer instanceof ArrayBuffer) {
buffer = Buffer.from(fileBuffer)
} else if (ArrayBuffer.isView(fileBuffer)) {View on GitHub (pinned to 726446b54c)
Solutions
- Gate the upload button in the renderer on a non-empty file selection; only call the IPC when a File with a real .name is present.
- If the filename is constructed from user input, validate it is non-empty after trim before sending.
- Add a unit test that asserts the renderer never dispatches the upload IPC with an empty filename.
Example fix
// renderer - before if (file) await upload(file.buffer, fileName.trim()) // after if (file && file.name && file.name.trim()) await upload(await file.arrayBuffer(), file.name)
Defensive patterns
Strategy: validation
Validate before calling
function isNonEmptyFileName(fileName: string): boolean {
return typeof fileName === 'string' && fileName.trim().length > 0
} Type guard
function isNonEmptyTrimmedString(s: unknown): s is string {
return typeof s === 'string' && s.trim().length > 0
} Prevention
- Disable the upload button in the UI until a File with a non-empty .name is selected.
- Assert file.name && file.name.trim() before constructing the IPC payload.
- In tests, never dispatch the upload IPC with '' or whitespace-only names.
When it happens
Trigger: The renderer IPC call sent fileName = "", " ", or a value derived from a missing File.name. A form that let the user proceed without selecting a file, or a synthetic upload in tests, would produce this.
Common situations: UI form submitted with no file chosen but the upload handler ran anyway; the filename was extracted from a path with a malformed split; a File object whose .name is empty (rare, but possible for programmatic Blobs).
Related errors
- Invalid MCP package upload: file name must be a string
- Invalid MCP package upload: file name cannot contain leading
- Invalid MCP package upload: file name cannot contain path se
- Invalid MCP package upload: file name contains unsupported c
- Invalid MCP package upload: expected a .${packageFormat} fil
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/6b20cd8d592945cc.
Report an issue: GitHub.