Errors¶
Every error svgwriter raises on purpose lives in svgwriter.errors (svg.errors.ThemeError, …). Each
subclasses the built-in exception a caller would expect, so except ValueError keeps working.
Every error svgwriter raises on purpose, in one place: svg.errors.<Name>.
Each subclasses the built-in exception a caller would expect (ValueError for bad values, KeyError
for failed lookups, AttributeError and TypeError for misspelled names), so except ValueError
keeps working.
Examples
>>> import svgwriter as svg
>>> try:
... svg.themes.get("drak")
... except svg.errors.UnknownNameError as error:
... print(type(error).__module__, error)
svgwriter.errors unknown theme 'drak'; did you mean 'dark'?
- exception DiagramToolError¶
Bases:
RuntimeErrorA diagram tool (Graphviz, Mermaid, PlantUML, D2, LaTeX) is missing or rejected the input.
- exception FFmpegError¶
Bases:
RuntimeErrorffmpegran but failed; the message carries the exit status and the tail of its error output.
- exception FFmpegNotFoundError¶
Bases:
RuntimeErrorffmpegis not installed or not onPATH.
- exception OfficeExtraError¶
Bases:
ImportErrorThe library for an Office format is not installed (
pip install "pysvgwriter[office]").
- exception PathSyntaxError(message: str, position: int)¶
Bases:
ValueErrorMalformed path data; records where in the text parsing failed.
- Parameters:
Examples
>>> import svgwriter as svg >>> try: ... svg.PathData("L1 1") ... except svg.errors.PathSyntaxError as error: ... print(error) path data must start with a moveto at offset 0
- exception ProjectError¶
Bases:
ValueErrorA project file is missing or invalid, or its entry cannot be loaded; the message names the file.
Examples
>>> import svgwriter as svg >>> issubclass(svg.errors.ProjectError, ValueError) True
- exception SVGParseError¶
Bases:
ValueErrorMalformed SVG input or, when strict, unsupported content.
Examples
>>> import svgwriter as svg >>> try: ... svg.parse("<svg") ... except svg.errors.SVGParseError: ... print("malformed") malformed
- exception SceneError¶
Bases:
ValueErrorA source defines no scene, or no scene with a requested name.
Examples
>>> import svgwriter as svg >>> issubclass(svg.errors.SceneError, ValueError) True
- exception ThemeError¶
Bases:
ValueErrorA theme that cannot be resolved: an unknown role or reference, a cycle, or a malformed value.
Examples
>>> import svgwriter as svg >>> try: ... svg.theme.Palette({"a": "{palette.b}"}) ... except svg.errors.ThemeError as error: ... print(error) palette.a: unknown reference {palette.b}
- exception UnknownAttributeError(owner: str, name: str, members: type | None = None)¶
Bases:
AttributeErrorAn attribute that is neither a Python member nor a known SVG attribute.
The “did you mean” suggestion is computed only when the message is shown, so
getattr(element, name, default)stays cheap.- Parameters:
Examples
>>> import svgwriter as svg >>> try: ... svg.rect(0, 0, 1, 1).widht ... except AttributeError as error: ... print("did you mean 'width'?" in str(error)) True >>> try: ... svg.text("A").fade_out() ... except AttributeError as error: ... print(str(error).split(": ", 1)[1]) fade_out is an animation; use element.animate.fade_out(...)
- exception UnknownKeywordError(owner: str, name: str, members: type | None = None)¶
Bases:
UnknownAttributeError,TypeErrorAn unknown keyword argument (likely a typo); custom attributes go in
attrs={...}.Examples
>>> import svgwriter as svg >>> try: ... svg.rect(0, 0, 1, 1, widht=3) ... except TypeError as error: ... print(type(error).__name__) UnknownKeywordError
- exception UnknownNameError¶
Bases:
KeyError,ValueErrorA name that no registry entry has; the message suggests the closest names.
It is both a
KeyError(a failed lookup) and aValueError(a bad argument value), so eitherexceptcatches it.Examples
>>> import svgwriter as svg >>> isinstance(svg.errors.UnknownNameError("x"), (KeyError, ValueError)) True