JPEG: improve error handling