Skip to content

rtk read <file> exits 1 with no output on a non-UTF-8 file, while --head-lines/--tail-lines on the same file are byte-exact #4065

Closed

Description

@sypsyp97

A plain read of a file that isn't valid UTF-8 exits 1 and prints nothing:

$ printf 'line one\nline two has a latin-1 byte: \xe9\nline three\n' > /tmp/nonutf8.log
$ rtk read /tmp/nonutf8.log
cat: /tmp/nonutf8.log: invalid utf-8 sequence of 1 bytes from index 38
$ echo $?
1

Same file, same binary, with a line window:

$ rtk read --head-lines 3 /tmp/nonutf8.log | cmp - /tmp/nonutf8.log && echo identical
identical

run() takes the byte path only when byte_line_window() returns Some, and that needs head_lines or tail_lines. A plain read has neither, falls through to String::from_utf8, and dies. The byte path is already byte-exact, it just isn't reachable without a window.

The hook decides which path a command lands on:

rewritten to result
cat f → rtk read f exit 1, no output
head -2 f → rtk read f --head-lines 2 works
tail -1 f → rtk read f --tail-lines 1 works

So cat on a log with one Latin-1 byte in it hands the agent an empty result, while head on the same file is fine. An empty result reads like an empty file.

CONTRIBUTING's Never Block rule covers this case: fall back to raw output instead of erroring out.

PR #1019 fixed it in April with a narrow gate (unfiltered, no window, no -n). A maintainer confirmed the bug on 2026-05-18 and asked for a rebase, the author rebased, and the branch then sat unreviewed until the stale bot closed it on 2026-09-14. I'll send a fresh PR against current develop.

  • develop @ d402152, macOS 26.6.2 arm64
  • also on 0.49.0 from brew, where the message reads stream did not contain valid UTF-8

Thanks!

Activity

  1. added
    bug
    good first issue
    on Sep 14, 2026
  2. rtk-wshm-sync-bot commented on Sep 14, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 93%

    Summary

    rtk read on a non-UTF-8 file exits 1 with no output because the byte-exact path is only reached when --head-lines/--tail-lines is set; should fall back to raw byte output per Never Block rule.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/commands/read.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. KuSh commented on Oct 31, 2026

    @KuSh
    Collaborator

    The numbered path has the same failure: the hook rewrites cat -n f to rtk read -n f, and for a file with one Latin-1 byte (printf 'caf\xe9\nok\n') that returns exit 1, empty stdout and cat: latin1.txt: invalid utf-8 sequence of 1 bytes from index 3. Native cat -n prints 22 bytes. Checked on develop 41e6912. The earlier narrow gate excluded -n, so a fix here needs to cover it as well.

  4. sypsyp97 commented on Nov 12, 2026

    @sypsyp97
    ContributorAuthor

    Fixed by #4066, released in 1.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibuggood first issuepriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions