fix: silence expected utf-8 errors when reading binary files#31
fix: silence expected utf-8 errors when reading binary files#31matiaspalmac wants to merge 1 commit intoTrixtyAI:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces noisy console errors in the desktop Git Explorer when users click binary/non-UTF-8 files, while keeping real read failures visible via explicit caller logging.
Changes:
- Call
read_filewith{ silent: true }to preventsafeInvokefrom logging expected UTF-8 decoding errors. - Preserve the existing UX fallback by opening the file with the
editor.bin_fileplaceholder on UTF-8 decode failures. - For non-UTF-8 read failures, log an explicit error from
GitExplorerComponentso genuine problems remain visible.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Closing in favor of #33 which bundles this fix together with the UX improvement for binary files (new tab type + descriptive placeholder). Keeping them separate would force a rebase on whichever merges second since both touch the same |
|
Closing in favor of #33, which bundles this fix together with the UX improvement for binary files (new 'binary' tab type + descriptive placeholder). Keeping them separate would force a rebase on whichever merges second since both touch the same read_file catch block. The combined change tells a single coherent story. |
## Changes Bundles two related improvements for how the app handles non-UTF-8 / binary files clicked from the explorer. **1. Quieter error path (supersedes #31).** `read_file` is now called with `{ silent: true }`, and the caller distinguishes the expected UTF-8 decoding error from real failures: - UTF-8 error → open the tab as a `"binary"` type (see below). - Any other error (permission denied, file locked, etc.) → `console.error` from the caller so real failures stay visible instead of being swallowed. Previously `safeInvoke` logged `[Tauri Invoke Error] read_file: "stream did not contain valid UTF-8"` for every binary-file click even though the flow was handled correctly — just noise. **2. Descriptive placeholder view.** Instead of rendering `--- BINARY ---` as literal text inside Monaco (with cursor, minimap, line numbers), binary files now show a centered message in the editor area — same UX pattern as VS Code. - `apps/desktop/src/context/AppContext.tsx`: extends `FileState.type` and `openFile` to accept `"binary"` alongside `"file"` and `"virtual"`. - `apps/desktop/src/components/EditorArea.tsx`: adds an `isBinaryTab` branch that renders a centered placeholder, skipping Monaco entirely. - `apps/desktop/src/addons/builtin.git-explorer/GitExplorerComponent.tsx`: silences `read_file`, routes UTF-8 errors to a `"binary"` tab, logs everything else. - `apps/desktop/src/api/builtin.l10n.ts`: rewrites `editor.bin_file` in `en` and `es` to a full-sentence, VS-Code-style message. Net: 4 files, small additions. ## Issues - fix #30 - fix #32
Changes
The file click handler in
GitExplorerComponent.tsxalready handles the "file isn't valid UTF-8" case by opening the tab with theeditor.bin_fileplaceholder. But because theread_fileinvoke was called without{ silent: true },safeInvokelogged[Tauri Invoke Error] read_file: "stream did not contain valid UTF-8"to the console before re-throwing — making every binary-file click look like a failure even though the UX is correct.{ silent: true }to theread_fileinvoke so the expected UTF-8 error isn't logged bysafeInvoke(same pattern used forget_git_statusin fix: guard tauri runtime and non-git folders #20).editor.bin_fileplaceholder.console.errorfrom the caller so real failures are still visible instead of being swallowed.Errorinstances produced by non-string rejections are handled correctly.No change to the hardcoded bin extension list — that's a separate concern. The silent-fallback path handles arbitrary binary files correctly on its own.
Issues