Repository navigation
Report Docker's diagnostic when writing to a container file fails - #775
Conversation
write_to_file ran docker exec without capturing output, so CalledProcessError.output was None and the handler raised AttributeError instead of the intended ValueError. Capture the output and build the message from stderr/stdout, tolerating empty values.
There was a problem hiding this comment.
Approved. A failed docker exec in write_to_file now raises the intended ValueError with Docker's diagnostic, instead of an AttributeError. That is what #745 asks for. Successful writes work as before, and the one caller (send_command in lean/commands/live/live.py) still gets a ValueError, as it did before.
Verified: both new tests fail on master and pass on this commit. A write to a missing directory in a real running container gives ValueError: Failed to write to command.json: bash: line 1: /missing/dir/command.json: No such file or directory, and a payload containing quotes and $ is still written literally.
Label risk:low: a small, easily reverted change that only affects the error path, with tests, green CI and an end-to-end run.
Once this merges, #758 (the original of this commit) can be closed.
There was a problem hiding this comment.
Approved; no blocking findings.
Independent verification:
python -m pytest -q -rs: 2,908 passed, 81 skipped. Both new regression tests fail with the base implementation and pass with this fix.python static_analysis.py: passed, with five existing unused-import warnings outside the changed files.- Tested end to end:
lean live command Sample --data '{}', with a forced container-file write failure, exits 1 and reportsFailed to write to command-….jsonwith Bash's diagnostic, without theNoneTypeerror. - Real Docker comparison: writing to a missing directory raises
ValueErrorwith the diagnostic on this commit versusAttributeErroron the base. Successful writes preserve the exact payload and filename on both, including apostrophes, dollar signs, backticks and backslashes. - Six additional output cases pass: absent streams, empty streams, stdout only, stderr only, both streams, and invalid UTF-8.
The change stays within #745 and leaves successful command submission unchanged.
Closes #745
DockerManager.write_to_filerandocker execwithout capturing its output. When the command failed,CalledProcessError.outputwasNoneand the handler's.decode()raisedAttributeError: 'NoneType' object has no attribute 'decode', which hid the intendedValueError.The
docker execcall now captures its output, and the message is built from stderr and stdout, with either one allowed to be empty orNone. The fix is the commit from #758 by @pcbeingused333, cherry-picked with its authorship kept.The only change in behavior is on failure: the
ValueErroris raised as intended and includes Docker's diagnostic, which before went straight to the terminal. Successful writes work as before.Testing
tests/components/docker/test_docker_manager.pycover a failure with no output and a failure with a Docker diagnostic. Both fail onmaster(theAttributeError) and pass with the change.python -m pytest -s -rs: 2908 passed, 81 skipped.python static_analysis.py: BUILD PASSED. Its 5 unused-import warnings are not in the changed files.ValueError: Failed to write to command.json: bash: line 1: /missing/dir/command.json: No such file or directorymaster:AttributeError: 'NoneType' object has no attribute 'decode'