Skip to content

Panic on startup: is_char_boundary assertion failed #25

@ShaneOxM

Description

@ShaneOxM

Bug Description

Keyless crashes immediately on launch with a panic related to UTF-8 character boundaries.

Error Message

thread 'main' panicked at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/alloc/src/string.rs:1461:13:
assertion failed: self.is_char_boundary(new_len)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Environment

  • OS: macOS (Darwin 25.1.0)
  • Version: keyless v0.3.0

Root Cause

Two locations truncate strings by byte position instead of UTF-8 character boundary:

1. keyless/src/tui/widgets/logs.rs:97

s.truncate(maxw - 1);

2. keyless/src/tui/dictating/eq.rs:87-88

let display_text = if preview_text.len() > width {
    &preview_text[..width]

When the truncation point falls in the middle of a multi-byte UTF-8 character (accented letters, emoji, etc.), Rust panics.

Proposed Fix

Find the nearest valid character boundary before truncating:

// Before
s.truncate(maxw - 1);

// After
let target = maxw - 1;
let boundary = s
    .char_indices()
    .map(|(i, _)| i)
    .take_while(|&i| i <= target)
    .last()
    .unwrap_or(0);
s.truncate(boundary);

Same pattern applies to the slice in eq.rs.

Happy to submit a PR if helpful.

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