You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/07/12 10:13:32 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #24943: Added exception catching to send default email if template file raises any exception

uranusjr commented on code in PR #24943:
URL: https://github.com/apache/airflow/pull/24943#discussion_r918795507


##########
airflow/models/taskinstance.py:
##########
@@ -2271,8 +2271,13 @@ def get_email_subject_content(
             def render(key: str, content: str) -> str:
                 if conf.has_option('email', key):
                     path = conf.get_mandatory_value('email', key)
-                    with open(path) as f:
-                        content = f.read()
+                    try:
+                        with open(path) as f:
+                            content = f.read()
+                    except FileNotFoundError:
+                        self.log.warning(f"Could not find email template file '{path}'. Using defaults...")
+                    except:

Review Comment:
   -1 to this blank catch. It’s probably worthwhile to catch all OSError, but this is way to broad.



##########
airflow/models/taskinstance.py:
##########
@@ -2271,8 +2271,13 @@ def get_email_subject_content(
             def render(key: str, content: str) -> str:
                 if conf.has_option('email', key):
                     path = conf.get_mandatory_value('email', key)
-                    with open(path) as f:
-                        content = f.read()
+                    try:
+                        with open(path) as f:
+                            content = f.read()
+                    except FileNotFoundError:
+                        self.log.warning(f"Could not find email template file '{path}'. Using defaults...")

Review Comment:
   Better to use `{path!r}`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org