Skip to content

Commit 33d8908

Browse files
committed
integrations/git: Log send_message errors to sys.stderr and a log file.
1 parent 06f8d75 commit 33d8908

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: zulip/integrations/git/post-receive

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ client = zulip.Client(
3131
client="ZulipGit/" + VERSION,
3232
)
3333

34+
log_file_path = os.path.join(os.path.dirname(__file__), "../post-receive.log")
35+
36+
37+
def log_error(message: str) -> None:
38+
print(message, file=sys.stderr)
39+
with open(log_file_path, "a") as log_file:
40+
log_file.write(f"{message}\n")
41+
3442

3543
def git_repository_name() -> str:
3644
path, name = os.path.split(os.getcwd())
@@ -94,7 +102,9 @@ def send_bot_message(oldrev: str, newrev: str, refname: str) -> None:
94102
"topic": destination.get("topic", destination.get("subject")),
95103
"content": message,
96104
}
97-
client.send_message(message_data)
105+
response = client.send_message(message_data)
106+
if response["result"] == "error":
107+
log_error(f"Failed to send Zulip message: {response['msg']}")
98108

99109

100110
for ln in sys.stdin:

0 commit comments

Comments
 (0)