Skip to content

feat(image): say why a web image failed to load on its placeholder - #94

Merged
delphinus merged 1 commit into
mainfrom
feat/image-load-error
Nov 26, 2026
Merged

delphinus merged 1 commit into
mainfrom
feat/image-load-error

Conversation

@delphinus

Copy link
Copy Markdown
Owner

Summary

A web image whose download failed sat on "Loading image..." for good. Now the placeholder says why:

  • an HTTP status, such as HTTP 404 (curl is run with -w %{http_code})
  • a named curl error, such as timed out, could not resolve host, could not connect, file too large (other codes as curl exit N)
  • not an image when a 200 brought back something else, such as a login page

The failure rebuilds the content, and the placeholder reads Failed to load image (HTTP 404) in the new MdRenderImageError group (fg from DiagnosticError, on the placeholder's background). When the sentence does not fit, the reason alone is shown.

A URL that failed is not asked for again on every rebuild or scroll — the failure rebuilds, and a rebuild that asked again would loop. Opening the view afresh retries it.

Changes

  • image.lua: keep the reason per URL (get_download_error), cleared on the next success
  • display_utils.lua: rebuild on a failed download; leave failed URLs out of the retries
  • content_builder.lua: write the reason on the placeholder
  • init.lua: MdRenderImageError
  • Help (en/ja): the highlight group, and a troubleshooting entry

Test plan

  • make test, stylua --check .
  • New tests: tests/image_test.lua (reasons, cleared on success), tests/image_load_error_test.lua (placeholder text and highlights)
  • Real curl against a local HTTP server: HTTP 404, not an image, could not connect
  • :MdRender tab headless: "Loading image..." turns into "Failed to load image (HTTP 404)", and the server sees one request only

Images inside tables are out of scope: their rows carry no loading message and stay blank.

🤖 Generated with Claude Code

A download that failed left the placeholder on "Loading image..." for
good. curl now prints the HTTP status, and the reason is kept per URL:
an HTTP status such as "HTTP 404", a named curl error such as "timed
out", or "not an image" when a 200 brought back something else. The
failure rebuilds the content, and the placeholder reads "Failed to load
image (HTTP 404)" in the new MdRenderImageError group.

A URL that failed is not asked for again on every rebuild or scroll,
which would loop; opening the view afresh retries it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@delphinus
delphinus force-pushed the feat/image-load-error branch from 2377c87 to b893116 Compare November 26, 2026 12:50
@delphinus
delphinus merged commit fc7b492 into main Nov 26, 2026
38 checks passed
@delphinus
delphinus deleted the feat/image-load-error branch November 26, 2026 12:57
denny0223 added a commit to denny0223/md-render.nvim that referenced this pull request Nov 26, 2026
Keep a failed download with the open preview so neighbouring images can
finish without requesting a broken URL on each layout change. An edit or
a fresh preview can retry. Give an existing transfer or completed file
precedence when another preview recovers the URL. Preserve direct callers'
retry behaviour and the separate limits for images and explicit videos.

Native splits can share one render buffer. Hand its failure state and
pending layout update to the surviving view so switching focus keeps the
document and its inline errors in place. Closing the last view ends that
attempt and lets a reopened preview show the latest response.

Reuse the Snacks picker's rendered line map while the source file and
scratch buffer are current. Detect saves and replacements on disk.
Retire placements when the picker rewrites its scratch buffer, before
the next source can reuse their extmark IDs.
Keep each source's redraw events with its own image state so a delayed
terminal probe cannot remove the next preview's handlers.

Follow up on #120 and delphinus#94.
denny0223 added a commit to denny0223/md-render.nvim that referenced this pull request Nov 28, 2026
Keep a failed download with the open preview so neighbouring images can
finish without requesting a broken URL on each layout change. An edit or
a fresh preview can retry. Give an existing transfer or completed file
precedence when another preview recovers the URL. Preserve direct callers'
retry behaviour and the separate limits for images and explicit videos.

Native splits can share one render buffer. Hand its failure state and
pending layout update to the surviving view so switching focus keeps the
document and its inline errors in place. Closing the last view ends that
attempt and lets a reopened preview show the latest response.

Reuse the Snacks picker's rendered line map while the source file and
scratch buffer are current. Detect saves and replacements on disk.
Retire placements when the picker rewrites its scratch buffer, before
the next source can reuse their extmark IDs.
Keep each source's redraw events with its own image state so a delayed
terminal probe cannot remove the next preview's handlers.

Follow up on #120 and delphinus#94.
denny0223 added a commit to denny0223/md-render.nvim that referenced this pull request Nov 29, 2026
Keep the failed request with the open source so neighbouring images can
finish without fetching the broken URL again. Editing the source or
closing its last view starts a new attempt. When native splits share one
render buffer, hand its failure state and pending layout update to the
surviving view.

Let a preview join an in-flight transfer or pick up a usable file another
process published while its request was failing. Direct download callers
still receive their own transfer result. A shared movie can play as video
while the image keeps its format error and its separate retry limit.

Reuse the Snacks picker's rendered line map while the source and scratch
buffer are current. Retire old placements and redraw handlers before a
different source can reuse their extmarks.

Follow up on #120 and delphinus#94.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant