pockethub/PocketHub · error · IOException
Cannot load SVG from stream
Error message
Cannot load SVG from stream
What it means
SvgDecoder.decode() parses an image stream with com.caverock.androidsvg. When AndroidSVG cannot parse the bytes as valid SVG it throws SVGParseException, which decode() rethrows as an IOException with this message. Glide then fails the load for that resource.
Solutions
- Confirm the URL actually serves valid SVG (check Content-Type: image/svg+xml and open the body).
- Fall back to a placeholder drawable when the SVG decode fails.
- Pre-validate or sanitize the SVG (e.g. via svg4everybody-style scrubbing) before decoding.
- Upgrade the androidsvg dependency if the SVG uses newer/unsupported features.
Example fix
// before
Glide.with(context).load(source).into(imageView);
// after
Glide.with(context)
.load(source)
.placeholder(R.drawable.image_loading_icon)
.error(R.drawable.image_loading_icon)
.into(imageView); Defensive patterns
Strategy: fallback
Validate before calling
// pre-check Content-Type before decoding:
// contentType?.contains("svg") == true Type guard
fun isSvg(contentType: String?, body: ByteArray): Boolean =
contentType?.contains("svg") == true || body.size > 4 && String(body, 0, 4) == "<svg" Try / catch
try {
val res = svgDecoder.decode(...)
} catch (e: IOException) {
showPlaceholder()
} Prevention
- Glide .error(placeholder) so failed SVGs degrade gracefully
- Verify image URLs serve image/svg+xml
- Beware .svgz / HTML-error-page responses
- Keep androidsvg library updated
When it happens
Trigger: An <img> in Markdown points at a URL whose body is not a valid SVG (HTML error page, PNG served with .svg extension, truncated download, or malformed XML).
Common situations: Server returns HTML 404 page with 200 status or wrong Content-Type; SVG uses unsupported features/external references; compressed .svgz served as .svg; network proxy strips content.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
AI-assisted analysis of pockethub/PocketHub@8228cb8f71 (2026-09-11).
Data as JSON: /api/errors/ac82f391a177c192.
Report an issue: GitHub.
Appendix: source
Thrown at app/src/main/java/com/github/pockethub/android/markwon/SvgDecoder.java:36
// TODO: Can we tell?
return true;
}
public Resource<SVG> decode(
@NonNull InputStream source, int width, int height, @NonNull Options options)
throws IOException {
try {
SVG svg = SVG.getFromInputStream(source);
if (width > 0) {
svg.setDocumentWidth(width);
}
if (height > 0) {
svg.setDocumentHeight(height);
}
return new SimpleResource<>(svg);
} catch (SVGParseException ex) {
throw new IOException("Cannot load SVG from stream", ex);
}
}
}View on GitHub (pinned to 8228cb8f71)