fix(pioss): fix undefined variable and file handle bugs in pioss endpoint - #1
Open
Ricardo-M-L wants to merge 1 commit into
Open
Ricardo-M-L wants to merge 1 commit into
Ricardo-M-L wants to merge 1 commit into
Conversation
…oint The pioss() Flask endpoint (Pi Object Storage System) had three bugs in the write (POST) and read (GET) handlers: 1. UnboundLocalError on file_Name — three error-log statements referenced 'file_Name' (undefined) instead of the parameter 'file_name'. Every exception path in the write handler crashed instead of logging. 2. NameError on response after network failure — if requests.post() raised, the code still evaluated response.status_code on the next line, crashing the handler. Added response = None in the except branch and guarded the status check with 'response and'. 3. Unhandled FileNotFoundError + leaked file handle in GET — the read handler opened files without checking existence (bare open(...) with no 'with' block), raising FileNotFoundError on missing files and leaking the fd on success. Added an os.path.exists check that returns HTTP 404, and wrapped the read in a 'with open(...) as f' context manager.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix 3 bugs: file_Name typo causing NameError, response used after exception, unprotected file open without with statement.