@@ -358,42 +358,42 @@ def _get_model_file(
358
358
)
359
359
return model_file
360
360
361
- except RepositoryNotFoundError :
361
+ except RepositoryNotFoundError as e :
362
362
raise EnvironmentError (
363
363
f"{ pretrained_model_name_or_path } is not a local folder and is not a valid model identifier "
364
364
"listed on 'https://huggingface.co/models'\n If this is a private repository, make sure to pass a "
365
365
"token having permission to this repo with `token` or log in with `huggingface-cli "
366
366
"login`."
367
- )
368
- except RevisionNotFoundError :
367
+ ) from e
368
+ except RevisionNotFoundError as e :
369
369
raise EnvironmentError (
370
370
f"{ revision } is not a valid git identifier (branch name, tag name or commit id) that exists for "
371
371
"this model name. Check the model page at "
372
372
f"'https://huggingface.co/{ pretrained_model_name_or_path } ' for available revisions."
373
- )
374
- except EntryNotFoundError :
373
+ ) from e
374
+ except EntryNotFoundError as e :
375
375
raise EnvironmentError (
376
376
f"{ pretrained_model_name_or_path } does not appear to have a file named { weights_name } ."
377
- )
378
- except HTTPError as err :
377
+ ) from e
378
+ except HTTPError as e :
379
379
raise EnvironmentError (
380
- f"There was a specific connection error when trying to load { pretrained_model_name_or_path } :\n { err } "
381
- )
382
- except ValueError :
380
+ f"There was a specific connection error when trying to load { pretrained_model_name_or_path } :\n { e } "
381
+ ) from e
382
+ except ValueError as e :
383
383
raise EnvironmentError (
384
384
f"We couldn't connect to '{ HUGGINGFACE_CO_RESOLVE_ENDPOINT } ' to load this model, couldn't find it"
385
385
f" in the cached files and it looks like { pretrained_model_name_or_path } is not the path to a"
386
386
f" directory containing a file named { weights_name } or"
387
387
" \n Checkout your internet connection or see how to run the library in"
388
388
" offline mode at 'https://huggingface.co/docs/diffusers/installation#offline-mode'."
389
- )
390
- except EnvironmentError :
389
+ ) from e
390
+ except EnvironmentError as e :
391
391
raise EnvironmentError (
392
392
f"Can't load the model for '{ pretrained_model_name_or_path } '. If you were trying to load it from "
393
393
"'https://huggingface.co/models', make sure you don't have a local directory with the same name. "
394
394
f"Otherwise, make sure '{ pretrained_model_name_or_path } ' is the correct path to a directory "
395
395
f"containing a file named { weights_name } "
396
- )
396
+ ) from e
397
397
398
398
399
399
# Adapted from
0 commit comments