{"record":{"id":"0a63c730a0749b1f","repo":"tldraw/tldraw","slug":"no-extension-found-in-file-path","errorCode":null,"errorMessage":"No extension found in file path","messagePattern":"No extension found in file path","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/vscode/extension/src/media.ts","lineNumber":44,"sourceCode":"\n// We use these types to enforce that we don't have any extra mime types in the EXTENSION_TO_MIME_TYPE map\n// and that we don't miss any mime types in the DEFAULT_SUPPORTED_MEDIA_TYPES array\ntype ExtensionMapMimeTypes =\n\t(typeof EXTENSION_TO_DEFAULT_MIME_TYPE)[keyof typeof EXTENSION_TO_DEFAULT_MIME_TYPE]\ntype _CheckMimeTypesCovered = DefaultSupportedMimeType extends ExtensionMapMimeTypes ? true : never\ntype _CheckNoExtraMimeTypes = ExtensionMapMimeTypes extends DefaultSupportedMimeType ? true : never\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst mimeTypesCovered: _CheckMimeTypesCovered = true\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst noExtraMimeTypes: _CheckNoExtraMimeTypes = true\n\nfunction isSupportedExtension(extension: string): extension is DefaultSupportedExtensions {\n\treturn extension in EXTENSION_TO_DEFAULT_MIME_TYPE\n}\n\nexport function getMimeTypeFromPath(filePath: string): string {\n\tconst extension = filePath.split('.').pop()?.toLowerCase()\n\tif (!extension) throw new Error('No extension found in file path')\n\n\tif (isSupportedExtension(extension)) {\n\t\treturn EXTENSION_TO_DEFAULT_MIME_TYPE[extension]\n\t}\n\tthrow new Error(`Unsupported file type: ${extension}`)\n}\n","sourceCodeStart":26,"sourceCodeEnd":51,"githubUrl":"https://github.com/tldraw/tldraw/blob/b31086b44731a7d1d9d46be4163ac8ef7417321d/apps/vscode/extension/src/media.ts#L26-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n//   getMimeTypeFromPath(file.name)   // file.name = 'screenshot' (no ext)\n//\n// after\n//   if (!file.name.includes('.')) return 'application/octet-stream'\n//   getMimeTypeFromPath(file.name)","handlingStrategy":"type-guard","validationCode":"function hasExtension(filePath: string): boolean {\n  const lastDot = filePath.lastIndexOf('.')\n  return lastDot > 0 && lastDot < filePath.length - 1\n}\n// if (!hasExtension(path)) return 'application/octet-stream'\n// getMimeTypeFromPath(path)","typeGuard":"function hasUsableExtension(filePath: string): boolean {\n  const parts = filePath.split('.')\n  return parts.length > 1 && parts[parts.length - 1].length > 0\n}","tryCatchPattern":"try {\n  const mime = getMimeTypeFromPath(path)\n} catch (e) {\n  if (e instanceof Error && e.message === 'No extension found in file path') {\n    return 'application/octet-stream'\n  }\n  throw e\n}","preventionTips":["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."],"tags":["validation","vscode-extension","mime-type","file-path"],"backgroundTag":null,"analyzedSha":"b31086b44731a7d1d9d46be4163ac8ef7417321d","analyzedAt":"2026-08-12T17:05:39.947Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}