marktext/marktext · warning · Error

not an image

Error message

not an image

What it means

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.

Source

Thrown at packages/muyajs/lib/utils/index.js:146

  const obj = {}
  Object.keys(object).forEach((key) => {
    if (typeof object[key] === 'object' && object[key] !== null) {
      if (Array.isArray(object[key])) {
        obj[key] = deepCopyArray(object[key])
      } else {
        obj[key] = deepCopy(object[key])
      }
    } else {
      obj[key] = object[key]
    }
  })
  return obj
}

export const loadImage = async(url, detectContentType = false) => {
  if (detectContentType) {
    const isImage = await checkImageContentType(url)
    if (!isImage) throw new Error('not an image')
  }
  return new Promise((resolve, reject) => {
    const image = new Image()
    image.onload = () => {
      resolve({
        url,
        width: image.width,
        height: image.height
      })
    }
    image.onerror = (err) => {
      reject(err)
    }
    image.src = url
  })
}

export const isOnline = () => {

View on GitHub (pinned to e52106fd1c)

Solutions

  1. Catch the error at the call site and show the user that the URL is not a valid image.
  2. Call loadImage without detectContentType when you trust the URL (e.g. user-confirmed image path).
  3. Pre-check the URL extension and Content-Type yourself and skip detection for known image extensions.
  4. Ensure the host returns the correct Content-Type (server-side fix) for the image asset.

Example fix

// before
const img = await loadImage(url, true)
// after
try {
  const img = await loadImage(url, true)
} catch (e) {
  if (e.message === 'not an image') {
    notice.notify({ message: 'URL does not point to an image' })
    return
  }
  throw e
}
Defensive patterns

Strategy: try-catch

Validate before calling

async function isImageUrl(url: string): Promise<boolean> {
  try { const r = await fetch(url, { method: 'HEAD' }); return r.ok && (r.headers.get('content-type') || '').startsWith('image/') }
  catch { return false }
}

Try / catch

try { return await loadImage(url, true) }
catch (e) { if (e.message === 'not an image') { warnUser(url); return null } throw e }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of marktext/marktext@e52106fd1c (2026-08-12). Data as JSON: /api/errors/80f56a9fd9538210. Report an issue: GitHub.