Show file metadata based preview with an error message when preview fails to render

This commit is contained in:
Kovid Goyal 2025-11-23 12:48:14 +05:30
parent 0c4cefd720
commit 7c52f727dc
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 2 additions and 1 deletions

View file

@ -157,7 +157,7 @@ func (p *ImagePreview) Render(h *Handler, x, y, width, height int) {
p.source_img = hd.img
p.custom_metadata = hd.metadata
if hd.err != nil {
p.render_err = NewErrorPreview(fmt.Errorf("Failed to render the preview with error: %w", hd.err))
p.render_err = NewFileMetadataPreviewWithError(p.abspath, p.metadata, fmt.Errorf("Failed to render the preview with error: %w", hd.err))
}
p.Render(h, x, y, width, height)
return

View file

@ -196,6 +196,7 @@ func NewFileMetadataPreviewWithError(abspath string, metadata fs.FileInfo, err e
h, t := write_file_metadata(abspath, metadata, nil)
ans := &MessagePreview{title: title, msg: h, trailers: t}
lines := style.WrapTextAsLines(err.Error(), 30, style.WrapOptions{})
ans.trailers = append(ans.trailers, "")
ans.trailers = append(ans.trailers, lines...)
return ans
}