@@ -507,8 +507,11 @@ def send(self):
507507
508508 # Read the content of the file if not already read
509509 if self .image is None :
510- with open (self .image_path , mode = 'rb' ) as file :
511- self .image = file .read ()
510+ try :
511+ with open (self .image_path , mode = 'rb' ) as file :
512+ self .image = file .read ()
513+ except OSError as exc :
514+ raise MessageError ('Fetching content of image failed' ) from exc
512515
513516 # Encrypt and upload image
514517 image_nonce , image_data = self ._pk_encrypt_raw (self .image )
@@ -595,8 +598,11 @@ def send(self):
595598
596599 # Read the content of the file if not already read
597600 if self .file_content is None :
598- with open (self .file_path , mode = 'rb' ) as file :
599- self .file_content = file .read ()
601+ try :
602+ with open (self .file_path , mode = 'rb' ) as file :
603+ self .file_content = file .read ()
604+ except OSError as exc :
605+ raise MessageError ('Fetching content of file failed' ) from exc
600606
601607 # Create symmetric key
602608 key , hex_key = Key .generate_secret_key ()
@@ -619,8 +625,11 @@ def send(self):
619625 if self .thumbnail_path is not None :
620626 # Read the content of the thumbnail file if not already read
621627 if self .thumbnail_content is None :
622- with open (self .thumbnail_path , mode = 'rb' ) as file :
623- self .thumbnail_content = file .read ()
628+ try :
629+ with open (self .thumbnail_path , mode = 'rb' ) as file :
630+ self .thumbnail_content = file .read ()
631+ except OSError as exc :
632+ raise MessageError ('Fetching content of thumbnail failed' ) from exc
624633
625634 # Encrypt and upload thumbnail
626635 _ , thumbnail_data = sk_encrypt_raw (key , self .thumbnail_content ,
0 commit comments