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) <noreply@anthropic.com>
This commit is contained in:
parent
32f034e2b2
commit
6045f67647
1 changed files with 7 additions and 1 deletions
8
crates/miyabi-core/src/protocol.rs
generated
8
crates/miyabi-core/src/protocol.rs
generated
|
|
@ -1211,7 +1211,13 @@ fn read_file_snippet(path: &Path, max_lines: usize) -> Result<String, Error> {
|
|||
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"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue