@samitouri / QOSAMI-WSL / commits / 20ca8997

Fix UnicodeEncodeError in create-release.py on cp1252 consoles (#40127)

* Fix UnicodeEncodeError in create-release.py on cp1252 consoles Reconfigure stdout/stderr with errors='backslashreplace' so commit messages containing characters outside the console code-page (e.g. U+2225) are escaped instead of crashing the script. Also redirect the 'failed to extract PR number' warning to stderr for consistency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix return type annotation for get_github_pr_message() Update the return annotation from str to tuple[str | None, str | None] to match the actual return values (pr_body, pr_number). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Ben Hillis committed Apr 7, 2026 at 12:11 UTC 20ca899748f825a402b4ddfa4864740848223709
1 file changed +7 -2
tools/devops/create-release.py
+7 -2
@@ -10,6 +10,11 @@ import functools
10 from git import Repo
11 from urllib.parse import urlparse
12
13 +# Reconfigure stdout/stderr to handle unencodable characters (e.g. Unicode in
14 +# commit messages) on consoles that use legacy code-pages such as cp1252.
15 +sys.stdout.reconfigure(errors='backslashreplace')
16 +sys.stderr.reconfigure(errors='backslashreplace')
17 +
18 @click.command()
19 @click.argument('version', required=True)
20 @click.argument('assets', default=None, nargs=-1)
@@ -78,10 +83,10 @@ def main(version: str, previous: str, max_message_lines: int, publish: bool, ass
83 print(f'\n{changes}')
84
85 @backoff.on_exception(backoff.expo, (requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.RequestException), max_time=600)
81 -def get_github_pr_message(token: str, message: str) -> str:
86 +def get_github_pr_message(token: str, message: str) -> tuple[str | None, str | None]:
87 match = re.search(r'\(#([0-9]+)\)', message)
88 if match is None:
84 - print(f'Warning: failed to extract GitHub PR number from message: {message}')
89 + print(f'Warning: failed to extract GitHub PR number from message: {message}', file=sys.stderr)
90 return None, None
91
92 pr_number = match.group(1)