mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-15 21:28:33 -05:00
[PR #1952] [MERGED] fix(tinytorch): UnboundLocalError when reading an HTTP error body fails #34676
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/harvard-edge/cs249r_book/pull/1952
Author: @Shashank-Tripathi-07
Created: 7/7/2026
Status: ✅ Merged
Merged: 7/10/2026
Merged by: @profvjreddi
Base:
dev← Head:fix/submission-unbound-error-body📝 Commits (1)
a53c941fix(tinytorch): UnboundLocalError when reading an HTTP error body fails📊 Changes
1 file changed (+3 additions, -1 deletions)
View changed files
📝
tinytorch/tito/core/submission.py(+3 -1)📄 Description
Summary
error_bodywas only assigned inside thetryblock (e.read().decode('utf-8')). If that read/decode itself raised (network hiccup mid-read, or a non-UTF-8 error body from the server), the broadexcept (json.JSONDecodeError, Exception)still ran and referencederror_bodyunconditionally, raisingUnboundLocalError-- a confusing crash in the middle oftito module complete's auto-sync step, instead of the clean "Upload failed" message this code is trying to produce.Fix
Initialize
error_body = ""before thetry, and only print it in theexceptblock when it's non-empty, so a read/decode failure degrades to "nothing to print" instead of crashing.Test plan
error_bodyis ever set -- old logic crashes withUnboundLocalError, new logic handles it silently; (2) read succeeding butjson.loadsfailing (the normal case this except block exists for) -- both old and new logic correctly print the error body.python -m py_compilepasses on the edited file.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.