Skip to content

Panic: 'end byte index 100 is not a char boundary' during search result rendering (src/search/mod.rs:1227) #148

Description

@tony-nexartis

Summary

codesearch search panics while rendering results when a matched chunk's context/snippet is truncated at a fixed byte offset that lands inside a multi-byte UTF-8 character.

Environment

  • codesearch v1.0.213+1 (macOS arm64 prebuilt binary)
  • Repo indexed locally (default settings), TypeScript codebase

Repro

Index a repo containing comment blocks with box-drawing characters (e.g. , U+2500, 3 bytes in UTF-8) near byte offset 100 of a chunk, then run a query matching that chunk:

codesearch search "plan universe"

Output

📄 .../src/lib/db/repositories/plan-universe.ts
   Lines 1067-1072 • Comment
   comment block (5 lines)
   ...
thread 'main' (2223939) panicked at src/search/mod.rs:1227:38:
end byte index 100 is not a char boundary; it is inside '─' (bytes 99..102 of string)

The matched file contains ASCII-art comment separators built from U+2500 characters; the panic occurs when the 100-byte truncation boundary falls inside one.

Expected

Truncate on a char boundary (e.g. s.char_indices().take_while(|(i,_)| *i <= 100).last()" or floor_char_boundary`) or on grapheme boundaries.

Notes

  • Process exits mid-output (partial results printed, then panic). Exit code observed as 0 in a pipeline, which can mask the failure for scripted consumers.
  • Happy to provide more details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions