Repository navigation
Commit e4576d0
authored
Log the reason the DLL directory could not be added on Windows (pytorch#22040)
### The bug
`extension/pybindings/portable_lib.py:69-73` passes the caught exception
to `logger.error()`, but the format string has no placeholder for it:
```python
logger.error(
"Failed to add the pybinding extension DLL to the search path. The extension may not work.",
e,
)
```
Python's logging formats the record lazily, so the mismatch is not
caught at the call site. When the handler actually runs,
`record.getMessage()` does `msg % self.args` and raises `TypeError: not
all arguments converted during string formatting`. Logging catches that
internally and prints a `--- Logging error ---` traceback instead of the
message.
The result is that the message is lost, the exception text is lost, and
stderr gets a traceback about logging rather than about the DLL search
path — precisely when someone is trying to work out why the extension
will not load on Windows.
### Reproduction
```
$ python -c "
import logging; logging.basicConfig()
try: raise OSError('path not found')
except Exception as e:
logging.getLogger('t').error('The extension may not work.', e)
"
--- Logging error ---
TypeError: not all arguments converted during string formatting
Message: 'The extension may not work.'
Arguments: (OSError('path not found'),)
```
### The fix
Add the placeholder, so the exception is interpolated into the message:
```
ERROR:t:Failed to add the pybinding extension DLL to the search path. The extension may not work: path not found
```
### Test plan
- Reproduced the `TypeError` and the swallowed message with the exact
call from `:70-73`.
- Confirmed the fixed call logs one ERROR line containing the exception
text, with no logging error raised.
- Windows-only path, so this cannot be exercised on a Linux or macOS CI
job. Verified by reproducing the logging behaviour directly rather than
by triggering a real `os.add_dll_directory` failure.1 parent bc69cf2 commit e4576d0
1 file changed
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
0 commit comments