{"record":{"id":"80f56a9fd9538210","repo":"marktext/marktext","slug":"not-an-image","errorCode":null,"errorMessage":"not an image","messagePattern":"not an image","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/muyajs/lib/utils/index.js","lineNumber":146,"sourceCode":"  const obj = {}\n  Object.keys(object).forEach((key) => {\n    if (typeof object[key] === 'object' && object[key] !== null) {\n      if (Array.isArray(object[key])) {\n        obj[key] = deepCopyArray(object[key])\n      } else {\n        obj[key] = deepCopy(object[key])\n      }\n    } else {\n      obj[key] = object[key]\n    }\n  })\n  return obj\n}\n\nexport const loadImage = async(url, detectContentType = false) => {\n  if (detectContentType) {\n    const isImage = await checkImageContentType(url)\n    if (!isImage) throw new Error('not an image')\n  }\n  return new Promise((resolve, reject) => {\n    const image = new Image()\n    image.onload = () => {\n      resolve({\n        url,\n        width: image.width,\n        height: image.height\n      })\n    }\n    image.onerror = (err) => {\n      reject(err)\n    }\n    image.src = url\n  })\n}\n\nexport const isOnline = () => {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/marktext/marktext/blob/e52106fd1cdcbd33c1258b7b0cdc7013c4c5d86c/packages/muyajs/lib/utils/index.js#L128-L164","documentation":"Thrown by muyajs loadImage() when detectContentType=true and checkImageContentType(url) returns false — i.e. a HEAD/GET request to the URL did not return an image MIME type. Used when the editor needs to verify that a remote URL actually points at an image before inserting it.","triggerScenarios":"loadImage called with detectContentType=true on a URL whose response Content-Type is not image/* (HTML 404 page, a redirect to a login page, a non-image file, or a server that omits Content-Type).","commonSituations":"Pasting a link to an image whose host requires auth and returns text/html. A dead image URL returning an HTML error page. A URL behind a redirect that does not preserve the image MIME. Network policies stripping Content-Type.","solutions":["Catch the error at the call site and show the user that the URL is not a valid image.","Call loadImage without detectContentType when you trust the URL (e.g. user-confirmed image path).","Pre-check the URL extension and Content-Type yourself and skip detection for known image extensions.","Ensure the host returns the correct Content-Type (server-side fix) for the image asset."],"exampleFix":"// before\nconst img = await loadImage(url, true)\n// after\ntry {\n  const img = await loadImage(url, true)\n} catch (e) {\n  if (e.message === 'not an image') {\n    notice.notify({ message: 'URL does not point to an image' })\n    return\n  }\n  throw e\n}","handlingStrategy":"try-catch","validationCode":"async function isImageUrl(url: string): Promise<boolean> {\n  try { const r = await fetch(url, { method: 'HEAD' }); return r.ok && (r.headers.get('content-type') || '').startsWith('image/') }\n  catch { return false }\n}","typeGuard":null,"tryCatchPattern":"try { return await loadImage(url, true) }\ncatch (e) { if (e.message === 'not an image') { warnUser(url); return null } throw e }","preventionTips":["Only enable detectContentType when the URL is untrusted.","Catch and degrade gracefully — show the user the URL was not an image.","Whitelist known image extensions to skip detection.","Ensure image hosts return the correct Content-Type."],"tags":["image","network","content-type","muyajs"],"backgroundTag":null,"analyzedSha":"e52106fd1cdcbd33c1258b7b0cdc7013c4c5d86c","analyzedAt":"2026-08-12T13:58:32.443Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}