Skip to content

fix(pioss): fix undefined variable and file handle bugs in pioss endpoint - #1

Open
Ricardo-M-L wants to merge 1 commit into
aslanpour:mainfrom
Ricardo-M-L:pr/fix-piagent
Open

Ricardo-M-L wants to merge 1 commit into
aslanpour:mainfrom
Ricardo-M-L:pr/fix-piagent

Conversation

@Ricardo-M-L

Copy link
Copy Markdown

Fix 3 bugs: file_Name typo causing NameError, response used after exception, unprotected file open without with statement.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant