@@ -358,42 +358,42 @@ def _get_model_file(
358358 )
359359 return model_file
360360
361- except RepositoryNotFoundError :
361+ except RepositoryNotFoundError as e :
362362 raise EnvironmentError (
363363 f"{ pretrained_model_name_or_path } is not a local folder and is not a valid model identifier "
364364 "listed on 'https://huggingface.co/models'\n If this is a private repository, make sure to pass a "
365365 "token having permission to this repo with `token` or log in with `huggingface-cli "
366366 "login`."
367- )
368- except RevisionNotFoundError :
367+ ) from e
368+ except RevisionNotFoundError as e :
369369 raise EnvironmentError (
370370 f"{ revision } is not a valid git identifier (branch name, tag name or commit id) that exists for "
371371 "this model name. Check the model page at "
372372 f"'https://huggingface.co/{ pretrained_model_name_or_path } ' for available revisions."
373- )
374- except EntryNotFoundError :
373+ ) from e
374+ except EntryNotFoundError as e :
375375 raise EnvironmentError (
376376 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 :
379379 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 :
383383 raise EnvironmentError (
384384 f"We couldn't connect to '{ HUGGINGFACE_CO_RESOLVE_ENDPOINT } ' to load this model, couldn't find it"
385385 f" in the cached files and it looks like { pretrained_model_name_or_path } is not the path to a"
386386 f" directory containing a file named { weights_name } or"
387387 " \n Checkout your internet connection or see how to run the library in"
388388 " offline mode at 'https://huggingface.co/docs/diffusers/installation#offline-mode'."
389- )
390- except EnvironmentError :
389+ ) from e
390+ except EnvironmentError as e :
391391 raise EnvironmentError (
392392 f"Can't load the model for '{ pretrained_model_name_or_path } '. If you were trying to load it from "
393393 "'https://huggingface.co/models', make sure you don't have a local directory with the same name. "
394394 f"Otherwise, make sure '{ pretrained_model_name_or_path } ' is the correct path to a directory "
395395 f"containing a file named { weights_name } "
396- )
396+ ) from e
397397
398398
399399# Adapted from
0 commit comments