From 6045f6764788cd411755601d9824b0cd97795580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=20=E9=A7=BF=E7=94=AB=20=28Shunsuke=20Hayashi=29?= Date: Fri, 10 Apr 2026 10:07:45 +0900 Subject: [PATCH] fix(protocol): handle non-UTF-8 files in read_file_snippet When reading Obsidian vault notes or source files, non-UTF-8 bytes caused a hard error. Now gracefully breaks on invalid UTF-8 lines and returns whatever was read so far. Closes #91 Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/miyabi-core/src/protocol.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/miyabi-core/src/protocol.rs b/crates/miyabi-core/src/protocol.rs index 8198168..5e3be09 100644 --- a/crates/miyabi-core/src/protocol.rs +++ b/crates/miyabi-core/src/protocol.rs @@ -1211,7 +1211,13 @@ fn read_file_snippet(path: &Path, max_lines: usize) -> Result { let reader = BufReader::new(file); let mut lines = Vec::new(); for line in reader.lines().take(max_lines) { - lines.push(line?); + match line { + Ok(l) => lines.push(l), + Err(_) => { + // Non-UTF-8 file (binary) — return what we have so far + break; + } + } } Ok(lines.join("\n")) }