Skip to content

fix: silence expected utf-8 errors when reading binary files#31

Closed
matiaspalmac wants to merge 1 commit intoTrixtyAI:mainfrom
matiaspalmac:fix/silent-read-file-utf8
Closed

fix: silence expected utf-8 errors when reading binary files#31
matiaspalmac wants to merge 1 commit intoTrixtyAI:mainfrom
matiaspalmac:fix/silent-read-file-utf8

Conversation

@matiaspalmac
Copy link
Copy Markdown
Contributor

Changes

The file click handler in GitExplorerComponent.tsx already handles the "file isn't valid UTF-8" case by opening the tab with the editor.bin_file placeholder. But because the read_file invoke was called without { silent: true }, safeInvoke logged [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.

  • Pass { silent: true } to the read_file invoke so the expected UTF-8 error isn't logged by safeInvoke (same pattern used for get_git_status in fix: guard tauri runtime and non-git folders #20).
  • Keep the UTF-8 path — open the tab with the editor.bin_file placeholder.
  • For non-UTF-8 errors (permission denied, file locked, etc.) explicitly console.error from the caller so real failures are still visible instead of being swallowed.
  • Coerce the caught value to string before matching, so Error instances 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

Copilot AI review requested due to automatic review settings April 19, 2026 03:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_file with { silent: true } to prevent safeInvoke from logging expected UTF-8 decoding errors.
  • Preserve the existing UX fallback by opening the file with the editor.bin_file placeholder on UTF-8 decode failures.
  • For non-UTF-8 read failures, log an explicit error from GitExplorerComponent so genuine problems remain visible.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@matiaspalmac
Copy link
Copy Markdown
Contributor Author

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 read_file catch block. The combined change tells a single coherent story.

@matiaspalmac
Copy link
Copy Markdown
Contributor Author

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.

@matiaspalmac matiaspalmac deleted the fix/silent-read-file-utf8 branch April 19, 2026 04:05
jmaxdev pushed a commit that referenced this pull request Apr 19, 2026
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Console error when clicking a binary file not in the hardcoded extension list

2 participants