Skip to content

Commit 83fc716

Browse files
authored
Sanitize exception logging and add input validation (#171)
1 parent f7eef52 commit 83fc716

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

jobs.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ def wrapper(*args, **kwargs):
9999
try:
100100
return func(*args, **kwargs)
101101
except Exception as e:
102-
logging.error(f"Function {func.__name__} failed: {e}")
102+
logging.error(
103+
"Function %s failed with exception %s",
104+
func.__name__,
105+
type(e).__name__,
106+
exc_info=True,
107+
)
103108
if attempt == RETRY_COUNT - 1:
104109
raise
105110
time.sleep(RETRY_SLEEP_SECONDS)
@@ -119,6 +124,10 @@ def get_team_members(team_slug: str):
119124

120125

121126
def get_slack_markdown_by_linear_username(username):
127+
# Handle missing or empty usernames explicitly to avoid unnecessary config access.
128+
if username is None or (isinstance(username, str) and not username.strip()):
129+
return "No Assignee"
130+
122131
config = load_config()
123132
for person in config["people"]:
124133
if config["people"][person]["linear_username"] == username:
@@ -127,6 +136,13 @@ def get_slack_markdown_by_linear_username(username):
127136

128137

129138
def get_slack_markdown_by_github_username(username):
139+
# Validate input to avoid propagating None or empty usernames.
140+
if username is None or (isinstance(username, str) and not username.strip()):
141+
logging.warning(
142+
"get_slack_markdown_by_github_username called with invalid username: %r",
143+
username,
144+
)
145+
return "Unknown user"
130146
config = load_config()
131147
for person in config["people"].values():
132148
if person.get("github_username") == username:
@@ -151,7 +167,11 @@ def _get_pr_diffs(issue):
151167
diffs.append(diff)
152168
except Exception as e: # pragma: no cover - network errors are ignored
153169
logging.error(
154-
"Failed to fetch diff for %s/%s#%s: %s", owner, repo, number, e
170+
"Failed to fetch diff for %s/%s#%s (error type: %s)",
171+
owner,
172+
repo,
173+
number,
174+
type(e).__name__,
155175
)
156176
return diffs
157177

0 commit comments

Comments
 (0)