fix(send): helpful error when --file gets a binary; document MEDIA: attachments (#45116)
A user passing an image to `hermes send --file` got a raw
UnicodeDecodeError ('utf-8 codec can't decode byte 0x89...') with no
hint that media delivery goes through the MEDIA:<path> directive.
- send_cmd: catch UnicodeDecodeError separately and print a usage error
explaining --file is for text bodies, with copy-pasteable MEDIA: and
[[as_document]] examples using the user's own path
- --file help text + epilog now mention MEDIA:
- docs: new 'Sending images and other media' section on the hermes send
reference page
This commit is contained in:
@@ -172,7 +172,7 @@ def test_file_not_found_is_usage_error(fake_tool, capsys, monkeypatch):
|
||||
assert "cannot read" in err.lower()
|
||||
|
||||
|
||||
def test_file_decode_error_is_usage_error(fake_tool, capsys, monkeypatch, tmp_path):
|
||||
def test_file_decode_error_suggests_media_directive(fake_tool, capsys, monkeypatch, tmp_path):
|
||||
monkeypatch.setattr("sys.stdin.isatty", lambda: True)
|
||||
bad = tmp_path / "bad-bytes.bin"
|
||||
bad.write_bytes(b"\xff\xfe\x00")
|
||||
@@ -182,7 +182,9 @@ def test_file_decode_error_is_usage_error(fake_tool, capsys, monkeypatch, tmp_pa
|
||||
send_cmd.cmd_send(args)
|
||||
assert exc.value.code == 2
|
||||
err = capsys.readouterr().err
|
||||
assert "cannot read" in err.lower()
|
||||
assert "not a text file" in err.lower()
|
||||
assert f"MEDIA:{bad}" in err
|
||||
assert "[[as_document]]" in err
|
||||
|
||||
|
||||
def test_tool_error_returns_failure_exit(monkeypatch, capsys):
|
||||
|
||||
Reference in New Issue
Block a user