8000 Print warning when mkdir fails instead of silently ignoring the error · matplotlib/matplotlib@8837d9a · GitHub
[go: up one dir, main page]

Skip to content

Commit 8837d9a

Browse files
committed
Print warning when mkdir fails instead of silently ignoring the error
For example, a user could have no more disk space, causing mkdir to fail, but not realize it because the error is silently discarded, and the subsequent warning would not indicate the actual issue.
1 parent 957271f commit 8837d9a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/matplotlib/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,26 +530,27 @@ def _get_config_or_cache_dir(xdg_base_getter):
530530
configdir = configdir.resolve()
531531
try:
532532
configdir.mkdir(parents=True, exist_ok=True)
533-
except OSError:
534-
pass
533+
except OSError as exc:
534+
_log.warning("mkdir -p failed for path %s: %s", configdir, exc)
535535
else:
536536
if os.access(str(configdir), os.W_OK) and configdir.is_dir():
537537
return str(configdir)
538+
_log.warning("%s is not a writable directory", configdir)
538539
# If the config or cache directory cannot be created or is not a writable
539540
# directory, create a temporary one.
540541
try:
541542
tmpdir = tempfile.mkdtemp(prefix="matplotlib-")
542543
except OSError as exc:
543544
raise OSError(
544-
f"Matplotlib requires access to a writable cache directory, but the "
545-
f"default path ({configdir}) is not a writable directory, and a temporary "
545+
f"Matplotlib requires access to a writable cache directory, but there "
546+
f"was an issue with the default path ({configdir}), and a temporary "
546547
f"directory could not be created; set the MPLCONFIGDIR environment "
547548
f"variable to a writable directory") from exc
548549
os.environ["MPLCONFIGDIR"] = tmpdir
549550
atexit.register(shutil.rmtree, tmpdir)
550551
_log.warning(
551-
"Matplotlib created a temporary cache directory at %s because the default path "
552-
"(%s) is not a writable directory; it is highly recommended to set the "
552+
"Matplotlib created a temporary cache directory at %s because there was "
553+
"an issue with the default path (%s); it is highly recommended to set the "
553554
"MPLCONFIGDIR environment variable to a writable directory, in particular to "
554555
"speed up the import of Matplotlib and to better support multiprocessing.",
555556
tmpdir, configdir)

0 commit comments

Comments
 (0)
0