Repository navigation
FIX: Handle non-UTF-8 output gracefully in run_subprocess - #14425
ishaaaan17 wants to merge 3 commits into
Conversation
When external commands or subprocesses emit non-UTF-8 binary output on stdout or stderr, decoding with default strict utf-8 raised UnicodeDecodeError and crashed run_subprocess. Use errors='replace' to decode gracefully without raising unhandled exceptions.
|
@ishaaaan17 I'm curious if there was a practical motivation for this fix? Like did you hit this error when using MNE-Python? |
|
hi @scott-huberty, to be honest with you, i did not face this in any normal MNE analysis pipeline. i noticed it while going through the error handling paths in the main reason was the external binaries on different platforms (like FreeSurfer or OpenMEEG tools called through adding but if you feel it is not needed or too defensive in practice, i understand, and i am happy to close it. |
reference issue (if any)
none
what does this implement/fix?
in
mne.utils.run_subprocess, the stdout and stderr are decoded usingdecode("utf-8"). when some external command gives non-utf-8 bytes, it raisesUnicodeDecodeErrorand the function crashes.in this pr i have added
errors="replace"to bothout.decode("utf-8")anderr.decode("utf-8"). i have also addedtest_run_subprocess_non_utf8to check that the non-utf-8 bytes on stdout and stderr are handled properly without raising any error.additional information
i wrote the fix myself, and gemini helped me to draft the initial test. after that i reviewed it, formatted it and tested everything locally.