Repository navigation
Conversation
_parse_elf is a context manager whose try/except wrapped the yield, so
the guard also covered the caller's own code inside the with block. A
ValueError, TypeError or OSError raised there was caught, the generator
yielded a second time, and contextlib replaced the real exception with
RuntimeError("generator didn't stop after throw()"), discarding the
original traceback.
Only a failure to open or parse the executable is reported as None, so
narrow the guard to open() plus ELFFile() and yield outside it. The file
stays open across the yield via contextlib.ExitStack, which also keeps
ef.interpreter readable inside the block.
Co-Authored-By: opencode <opencode@users.noreply.github.com>
768d8f1 to
549fae0
Compare
|
Hi — this is 2 files (+35/−5) at 549fae0, unchanged since I pushed it.
The fix narrows the I considered keeping the broad guard and re-raising the caller's error instead, which looked noisier than narrowing the scope. Is there anything you would like changed before this can go in? |
There was a problem hiding this comment.
Ten context-manager checks passed using a real local ELF executable and a nonexistent-path fixture. Caller OSError, TypeError, ValueError and RuntimeError propagated as the same exception objects on both setup paths. Opened ELF streams were closed after normal exit and caller failure; missing-file setup yielded None normally. I used Python 3.12.14 against commit 549fae0.
The unsuccessful-setup path is worth a regression too: an exception raised by the with-body after receiving None should propagate once, just like the successful parse path, rather than be mistaken for a new parsing failure or trigger a second yield. I checked both paths against fetched PR source with standalone assertions; I did not run the full pytest suite.
|
Thanks @Wkhanex for checking both setup paths. Added the missing-path regression in I independently ran the new cases on base |
_parse_elfcatchesOSError,TypeErrorandValueErroracross itsyield, so the same errors raised by a caller inside thewithblock are replaced byRuntimeError: generator didn't stop after throw().Narrow the guard to opening and parsing the executable.
ExitStackkeeps the stream open while the caller uses the ELF object and closes it on either normal exit or caller failure. Missing or invalid executables still yieldNone.Regression tests read a real ELF fixture and a missing path, then raise each of
OSError,TypeError,ValueErrorandRuntimeError. They check that the original exception object propagates, including after receivingNone, and that opened streams close. A separate test covers normal-exit closure.On base
ea25b7d, the new exception cases produce 3 failures and 5 passes: valid-ELF callerOSError,TypeErrorandValueErrorbecome the unrelated context-manager error. The missing-file cases already pass on base.Validation on Python 3.11.15:
_manylinux.py.The current in-tree callers only read cached ELF attributes, so this error path is latent there. The change preserves their behavior while keeping errors from the context-manager body intact. Other Python versions, Linux and the property-test suite were not run locally.