tldraw/tldraw · error · Error
No extension found in file path
Error message
No extension found in file path
What it means
Thrown by getMimeTypeFromPath when the supplied file path yields no usable extension. The extension is derived via filePath.split('.').pop(); if the result is empty (empty string path, or a path ending in a dot), the function cannot determine a MIME type and throws.
Source
Thrown at apps/vscode/extension/src/media.ts:44
// We use these types to enforce that we don't have any extra mime types in the EXTENSION_TO_MIME_TYPE map
// and that we don't miss any mime types in the DEFAULT_SUPPORTED_MEDIA_TYPES array
type ExtensionMapMimeTypes =
(typeof EXTENSION_TO_DEFAULT_MIME_TYPE)[keyof typeof EXTENSION_TO_DEFAULT_MIME_TYPE]
type _CheckMimeTypesCovered = DefaultSupportedMimeType extends ExtensionMapMimeTypes ? true : never
type _CheckNoExtraMimeTypes = ExtensionMapMimeTypes extends DefaultSupportedMimeType ? true : never
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const mimeTypesCovered: _CheckMimeTypesCovered = true
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const noExtraMimeTypes: _CheckNoExtraMimeTypes = true
function isSupportedExtension(extension: string): extension is DefaultSupportedExtensions {
return extension in EXTENSION_TO_DEFAULT_MIME_TYPE
}
export function getMimeTypeFromPath(filePath: string): string {
const extension = filePath.split('.').pop()?.toLowerCase()
if (!extension) throw new Error('No extension found in file path')
if (isSupportedExtension(extension)) {
return EXTENSION_TO_DEFAULT_MIME_TYPE[extension]
}
throw new Error(`Unsupported file type: ${extension}`)
}
View on GitHub (pinned to b31086b447)
Solutions
- Ensure the file path passed to getMimeTypeFromPath includes a real extension (filename.ext).
- Guard callers: check filePath.includes('.') and has a non-empty segment after the last dot before calling.
- If extensionless files are valid in your flow, map them to a default MIME type before calling instead of relying on this function.
- Log the offending path at the call site to find which upstream code produced an empty/extensionless name.
Example fix
// before
// getMimeTypeFromPath(file.name) // file.name = 'screenshot' (no ext)
//
// after
// if (!file.name.includes('.')) return 'application/octet-stream'
// getMimeTypeFromPath(file.name) Defensive patterns
Strategy: type-guard
Validate before calling
function hasExtension(filePath: string): boolean {
const lastDot = filePath.lastIndexOf('.')
return lastDot > 0 && lastDot < filePath.length - 1
}
// if (!hasExtension(path)) return 'application/octet-stream'
// getMimeTypeFromPath(path) Type guard
function hasUsableExtension(filePath: string): boolean {
const parts = filePath.split('.')
return parts.length > 1 && parts[parts.length - 1].length > 0
} Try / catch
try {
const mime = getMimeTypeFromPath(path)
} catch (e) {
if (e instanceof Error && e.message === 'No extension found in file path') {
return 'application/octet-stream'
}
throw e
} Prevention
- Validate the path has an extension at the call site before invoking getMimeTypeFromPath.
- Filter drop/paste events to files with recognized extensions before processing.
- Log extensionless paths to find upstream sources of bad data.
- Default to a generic MIME type rather than throwing for extensionless files if your UX allows.
When it happens
Trigger: Calling getMimeTypeFromPath with an empty string, a path with no dot (e.g. 'README'), or a trailing-dot path (e.g. 'file.'). The pop() returns '' in these cases and the !extension guard fires.
Common situations: A drag-and-drop or paste handler passed a file name without an extension; a path was constructed by stripping the extension before calling this function; a data transfer provided a synthetic name; the path came from a URL without a file extension.
Related errors
- Unsupported file type: ${extension}
- Content-type not right: ${contentType}
- No tldraw account for: ${unknown.join(', ')}
- User not found ${q}
- objectId must be a 64-char lowercase hex string
AI-assisted analysis of tldraw/tldraw@b31086b447 (2026-08-12).
Data as JSON: /api/errors/0a63c730a0749b1f.
Report an issue: GitHub.