-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved error handling on social plugin (#6818)
* fix(social): CairoSVG OSError handling in social plugin Related issue: #6817 Co-authored-by: Guts <[email protected]> * feat(docs): Add troubleshooting guide for CairoSVG crash --------- Co-authored-by: Kamil Krzyśków <[email protected]> Co-authored-by: Guts <[email protected]> Co-authored-by: Martin Donath <[email protected]>
- Loading branch information
1 parent
abfac1a
commit a2cb35d
Showing
6 changed files
with
367 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import inspect | ||
import os | ||
import shutil | ||
import subprocess | ||
from ctypes import util | ||
|
||
|
||
class CustomPopen(subprocess.Popen): | ||
|
||
def __init__(self, *args, **kwargs): | ||
print(f"Subprocess command:\n {' '.join(args[0])}") | ||
super().__init__(*args, **kwargs) | ||
|
||
def communicate(self, *args, **kwargs): | ||
out, _ = super().communicate(*args, **kwargs) | ||
out = out.rstrip() | ||
print("Subprocess output:") | ||
if out: | ||
print(f" {os.fsdecode(out)}") | ||
else: | ||
print(f" Output is empty") | ||
return out, _ | ||
|
||
def __getattribute__(self, name_): | ||
att = super().__getattribute__(name_) | ||
if name_ == "stdout" and att is not None: | ||
att.read = self.read_wrapper(att.read) | ||
return att | ||
|
||
@staticmethod | ||
def read_wrapper(func): | ||
|
||
if func.__name__ == "wrapper": | ||
return func | ||
|
||
def wrapper(*args, **kwargs): | ||
output = func(*args, **kwargs) | ||
print("Subprocess output:") | ||
for line_ in os.fsdecode(output).split("\n"): | ||
print(line_) | ||
return output | ||
|
||
return wrapper | ||
|
||
|
||
subprocess.Popen = CustomPopen | ||
|
||
print("ctypes.util script with the find_library:") | ||
print(inspect.getsourcefile(util.find_library), end="\n\n") | ||
|
||
print("find_library function:") | ||
func_lines = list(map(str.rstrip, inspect.getsourcelines(util.find_library)[0])) | ||
indent = len(func_lines[0]) - len(func_lines[0].lstrip()) | ||
for line in func_lines: | ||
print(line.replace(" " * indent, "", 1)) | ||
|
||
library_names = ("cairo-2", "cairo", "libcairo-2") | ||
filenames = ("libcairo.so.2", "libcairo.2.dylib", "libcairo-2.dll") | ||
c_compiler = shutil.which("gcc") or shutil.which("cc") | ||
ld_env = os.environ.get("LD_LIBRARY_PATH") | ||
first_found = "" | ||
|
||
print("\nLD_LIBRARY_PATH =", ld_env, end="\n\n") | ||
|
||
for name in library_names: | ||
if hasattr(util, "_findSoname_ldconfig"): | ||
result = util._findSoname_ldconfig(name) | ||
print(f"_findSoname_ldconfig({name}) ->", result) | ||
if result: | ||
print(f"Found {result}") | ||
if not first_found: | ||
first_found = result | ||
print("---") | ||
if c_compiler and hasattr(util, "_findLib_gcc"): | ||
result = util._findLib_gcc(name) | ||
print(f"_findLib_gcc({name}) ->", result) | ||
if result and hasattr(util, "_get_soname"): | ||
result = util._get_soname(result) | ||
if result: | ||
print(f"Found {result}") | ||
if not first_found: | ||
first_found = result | ||
print("---") | ||
if hasattr(util, "_findLib_ld"): | ||
result = util._findLib_ld(name) | ||
print(f"_findLib_ld({name}) ->", result) | ||
if result and hasattr(util, "_get_soname"): | ||
result = util._get_soname(result) | ||
if result: | ||
print(f"Found {result}") | ||
if not first_found: | ||
first_found = result | ||
print("---") | ||
if hasattr(util, "_findLib_crle"): | ||
result = util._findLib_crle(name, False) | ||
print(f"_findLib_crle({name}) ->", result) | ||
if result and hasattr(util, "_get_soname"): | ||
result = util._get_soname(result) | ||
if result: | ||
print(f"Found {result}") | ||
if not first_found: | ||
first_found = result | ||
print("---") | ||
|
||
if first_found: | ||
filenames = (first_found,) + filenames | ||
|
||
print(f"The path is {first_found or 'not found'}") | ||
print("List of files that FFI will try to load:") | ||
for filename in filenames: | ||
print("-", filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
from ctypes.macholib import dyld | ||
from itertools import chain | ||
|
||
library_names = ("cairo-2", "cairo", "libcairo-2") | ||
filenames = ("libcairo.so.2", "libcairo.2.dylib", "libcairo-2.dll") | ||
first_found = "" | ||
names = [] | ||
|
||
for name in library_names: | ||
names += [ | ||
"lib%s.dylib" % name, | ||
"%s.dylib" % name, | ||
"%s.framework/%s" % (name, name), | ||
] | ||
|
||
for name in names: | ||
for path in dyld.dyld_image_suffix_search( | ||
chain( | ||
dyld.dyld_override_search(name), | ||
dyld.dyld_executable_path_search(name), | ||
dyld.dyld_default_search(name), | ||
) | ||
): | ||
if os.path.isfile(path): | ||
print(f"Found: {path}") | ||
if not first_found: | ||
first_found = path | ||
continue | ||
|
||
try: | ||
if dyld._dyld_shared_cache_contains_path(path): | ||
print(f"Found: {path}") | ||
if not first_found: | ||
first_found = path | ||
continue | ||
except NotImplementedError: | ||
pass | ||
|
||
print(f"Doesn't exist: {path}") | ||
print("---") | ||
|
||
if first_found: | ||
filenames = (first_found,) + filenames | ||
|
||
print(f"The path is {first_found or 'not found'}") | ||
print("List of files that FFI will try to load:") | ||
for filename in filenames: | ||
print("-", filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
library_names = ("cairo-2", "cairo", "libcairo-2") | ||
filenames = ("libcairo.so.2", "libcairo.2.dylib", "libcairo-2.dll") | ||
first_found = "" | ||
names = [] | ||
|
||
for name in library_names: | ||
if name.lower().endswith(".dll"): | ||
names += [name] | ||
else: | ||
names += [name, name + ".dll"] | ||
|
||
for name in names: | ||
for path in os.environ["PATH"].split(os.pathsep): | ||
resolved_path = os.path.join(path, name) | ||
if os.path.exists(resolved_path): | ||
print(f"Found: {resolved_path}") | ||
if not first_found: | ||
first_found = resolved_path | ||
continue | ||
print(f"Doesn't exist: {resolved_path}") | ||
print("---") | ||
|
||
if first_found: | ||
filenames = (first_found,) + filenames | ||
|
||
print(f"The path is {first_found or 'not found'}") | ||
print("List of files that FFI will try to load:") | ||
for filename in filenames: | ||
print("-", filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.