aboutsummaryrefslogtreecommitdiffstats
path: root/modules/safe.py
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2023-05-29 05:54:13 +0000
committerAarni Koskela <akx@iki.fi>2023-05-29 06:17:30 +0000
commit00dfe27f59727407c5b408a80ff2a262934df495 (patch)
treeaae9d324a719c7e500f4a0c45821851bc6e41ee0 /modules/safe.py
parentb957dcfece29c84ac0cfcd5a69475ff8684c531f (diff)
downloadstable-diffusion-webui-gfx803-00dfe27f59727407c5b408a80ff2a262934df495.tar.gz
stable-diffusion-webui-gfx803-00dfe27f59727407c5b408a80ff2a262934df495.tar.bz2
stable-diffusion-webui-gfx803-00dfe27f59727407c5b408a80ff2a262934df495.zip
Add & use modules.errors.print_error where currently printing exception info by hand
Diffstat (limited to 'modules/safe.py')
-rw-r--r--modules/safe.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/modules/safe.py b/modules/safe.py
index e8f50774..b596f565 100644
--- a/modules/safe.py
+++ b/modules/safe.py
@@ -2,8 +2,6 @@
import pickle
import collections
-import sys
-import traceback
import torch
import numpy
@@ -11,6 +9,8 @@ import _codecs
import zipfile
import re
+from modules.errors import print_error
+
# PyTorch 1.13 and later have _TypedStorage renamed to TypedStorage
TypedStorage = torch.storage.TypedStorage if hasattr(torch.storage, 'TypedStorage') else torch.storage._TypedStorage
@@ -136,17 +136,20 @@ def load_with_extra(filename, extra_handler=None, *args, **kwargs):
check_pt(filename, extra_handler)
except pickle.UnpicklingError:
- print(f"Error verifying pickled file from {filename}:", file=sys.stderr)
- print(traceback.format_exc(), file=sys.stderr)
- print("-----> !!!! The file is most likely corrupted !!!! <-----", file=sys.stderr)
- print("You can skip this check with --disable-safe-unpickle commandline argument, but that is not going to help you.\n\n", file=sys.stderr)
+ print_error(
+ f"Error verifying pickled file from {filename}\n"
+ "-----> !!!! The file is most likely corrupted !!!! <-----\n"
+ "You can skip this check with --disable-safe-unpickle commandline argument, but that is not going to help you.\n\n",
+ exc_info=True,
+ )
return None
-
except Exception:
- print(f"Error verifying pickled file from {filename}:", file=sys.stderr)
- print(traceback.format_exc(), file=sys.stderr)
- print("\nThe file may be malicious, so the program is not going to read it.", file=sys.stderr)
- print("You can skip this check with --disable-safe-unpickle commandline argument.\n\n", file=sys.stderr)
+ print_error(
+ f"Error verifying pickled file from {filename}\n"
+ f"The file may be malicious, so the program is not going to read it.\n"
+ f"You can skip this check with --disable-safe-unpickle commandline argument.\n\n",
+ exc_info=True,
+ )
return None
return unsafe_torch_load(filename, *args, **kwargs)
@@ -190,4 +193,3 @@ with safe.Extra(handler):
unsafe_torch_load = torch.load
torch.load = load
global_extra_handler = None
-