Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sxyazi
Copy link
Owner

@sxyazi sxyazi commented Nov 30, 2025

Yazi relies on file(1) to detect a file's MIME type, and without a MIME type, no file can be previewed or opened.

Most *nix systems have file bundled by default, but Windows users need to install it manually. In the past I've received many invalid bug reports caused by file not being installed:

I'm a bit tired of repeating "RTFM!!!" over and over, so let's fix this now :P

This PR changes the mime.local plugin to set a placeholder MIME type of null/file1-not-found for files when the file command cannot be found, and adds a new previewer rule:

{ mime = "null/*", run = "null" },

The null previewer just prints a message in the preview pane to prompt the user to install file(1). And since the file has a MIME type now, so it can also be opened (with the fallback open rule):

{ url = "*", use = [ "open", "reveal" ] },

Hopefully, this will save time for both users and maintainers when this issue is encountered again, reduce the number of invalid bug reports, and bring world peace!

Copy link

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 introduces a new null plugin to serve as a general-purpose error handler for MIME type detection failures. When the file command is not installed (common on Windows), files are assigned a placeholder MIME type of null/file1-not-found, allowing the null plugin to display a helpful error message in the preview pane instead of silently failing.

Key changes:

  • New null.lua plugin that displays an error message when MIME detection fails
  • Refactoring of mime-local.lua to handle file command not found errors gracefully by setting placeholder MIME types
  • Error serialization format changed from snake_case to PascalCase for consistency

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
yazi-plugin/preset/plugins/null.lua New plugin that displays error messages for files with null/* MIME types
yazi-plugin/preset/plugins/mime-local.lua Refactored to use module methods and added placeholder MIME type assignment when file command is not found
yazi-fs/src/error/serde.rs Changed error kind serialization format from snake_case to PascalCase and updated deserialization to handle errors
yazi-fs/src/error/error.rs Added custom() constructor and kind_str() helper method
yazi-binding/src/error.rs Added Error.fs() constructor for Lua and kind field getter
yazi-plugin/src/loader/loader.rs Registered the new null plugin
yazi-config/preset/yazi-default.toml Added preview and spotter rules for null/* MIME types

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

end

local updates = {}
for i = 1, math.max(#urls, #paths) do
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

The loop iterates up to math.max(#urls, #paths), but this can cause nil access when one array is shorter than the other. If #urls < #paths, then urls[i] will be nil for indices beyond #urls, and if both are nil at index i, the expression urls[i] or paths[i] would try to use paths[i] which might also be nil. The logic should ensure valid indices for both arrays. Consider using separate loops or bounds checking: for i = 1, math.min(math.max(#urls, #paths), math.max(1, #urls > 0 and #urls or #paths)) do or simply for i = 1, #paths do since paths is always populated based on the fetch function logic.

Suggested change
for i = 1, math.max(#urls, #paths) do
for i = 1, #paths do

Copilot uses AI. Check for mistakes.
@sxyazi sxyazi merged commit 0fb652d into main Nov 30, 2025
6 checks passed
@sxyazi sxyazi deleted the pr-96106b38 branch November 30, 2025 06:44
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants