mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-08-04 19:45:08 -04:00
Improved error handling on social plugin (#6818)
* fix(social): CairoSVG OSError handling in social plugin Related issue: #6817 Co-authored-by: Guts <1596222+Guts@users.noreply.github.com> * feat(docs): Add troubleshooting guide for CairoSVG crash --------- Co-authored-by: Kamil Krzyśków <kamilzary@gmail.com> Co-authored-by: Guts <1596222+Guts@users.noreply.github.com> Co-authored-by: Martin Donath <martin.donath@squidfunk.com>
This commit is contained in:
@@ -49,14 +49,25 @@ from mkdocs.plugins import BasePlugin
|
||||
from mkdocs.utils import copy_file
|
||||
from shutil import copyfile
|
||||
from tempfile import NamedTemporaryFile
|
||||
try:
|
||||
from cairosvg import svg2png
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from .config import SocialConfig
|
||||
|
||||
try:
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
except ImportError as e:
|
||||
import_errors = {repr(e)}
|
||||
else:
|
||||
import_errors = set()
|
||||
|
||||
cairosvg_error: str = ""
|
||||
|
||||
try:
|
||||
from cairosvg import svg2png
|
||||
except ImportError as e:
|
||||
import_errors.add(repr(e))
|
||||
except OSError as e:
|
||||
cairosvg_error = str(e)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Classes
|
||||
@@ -76,10 +87,18 @@ class SocialPlugin(BasePlugin[SocialConfig]):
|
||||
return
|
||||
|
||||
# Check dependencies
|
||||
if "Image" not in globals():
|
||||
if import_errors:
|
||||
raise PluginError(
|
||||
"Required dependencies of \"social\" plugin not found. "
|
||||
"Install with: pip install \"mkdocs-material[imaging]\""
|
||||
"Required dependencies of \"social\" plugin not found:\n"
|
||||
+ str("\n".join(map(lambda x: "- " + x, import_errors)))
|
||||
+ "\n\n--> Install with: pip install \"mkdocs-material[imaging]\""
|
||||
)
|
||||
|
||||
if cairosvg_error:
|
||||
raise PluginError(
|
||||
"\"cairosvg\" Python module is installed, but it crashed with:\n"
|
||||
+ cairosvg_error
|
||||
+ "\n\n--> Check out the troubleshooting guide: https://t.ly/MfX6u"
|
||||
)
|
||||
|
||||
# Move color options
|
||||
|
||||
Reference in New Issue
Block a user