Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove escape characters from the logs #831

Closed
1 task
teto opened this issue Mar 19, 2024 · 11 comments · Fixed by #832
Closed
1 task

remove escape characters from the logs #831

teto opened this issue Mar 19, 2024 · 11 comments · Fixed by #832
Labels
feature New feature request

Comments

@teto
Copy link

teto commented Mar 19, 2024

Please describe the problem you're trying to solve

hi,

as excited as the first time for yazi, clearly the best out there. So I decided for fun and convenience to try implementing a lua previewer for some files.
Of course it doesn't work so I tried looking at the logs to have more details:

  �[2m2024-02-18T22:48:47.999790Z�[0m �[31mERROR�[0m �[1;31myazi_scheduler::preload::preload�[0m�[31m: �[31mPreload task `mime` returned 2�[0m
    �[2;3mat�[0m yazi-scheduler/src/preload/preload.rs:42

  �[2m2024-02-20T13:43:47.320860Z�[0m �[31mERROR�[0m �[1;31myazi_scheduler::preload::preload�[0m�[31m: �[31mPreload task `pdf` returned 0�[0m
    �[2;3mat�[0m yazi-scheduler/src/preload/preload.rs:42

  �[2m2024-02-26T17:44:33.538746Z�[0m �[31mERROR�[0m �[1;31myazi_scheduler::preload::preload�[0m�[31m: �[31mPreload task `mime` returned 2�[0m
    �[2;3mat�[0m yazi-scheduler/src/preload/preload.rs:42

First of all I think yazi shouldn't use those escape charaters or is it intended ?
And I found no information about my plugins.
I tried yazi --debug with no more information.

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

Would be nice to list the plugins in the log at startup, or in --debug. Or even add subcommands like yazi plugin list or yazi config previewers

Additional context

version 0.2.4
No response

@sxyazi
Copy link
Owner

sxyazi commented Mar 22, 2024

Thanks for the report, should be fixed in #832

yazi plugin list conflicts a bit with the current parameters; it opens "plugin" as a directory in Yazi lol. I plan to have a separate program in the future to manage Yazi's plugins/themes.

@teto
Copy link
Author

teto commented Mar 22, 2024

ty for PR.

any advice on how to debug lua plugins ?
I cant find a way to get any feedback on what's wrong, if my plugin is even found/loaded etc

@sxyazi
Copy link
Owner

sxyazi commented Mar 23, 2024

If the plugin does not exist or fails to execute, an error message will be appended to the log file. For example, if I specify a nonexistent test plugin for audio:

# yazi.toml
[plugin]
prepend_previewers = [
	{ mime = "audio/*", run = "test" },
]

I get the following log when I hover over the audio file:

ERROR yazi_plugin::isolate::peek: plugin not found: test

@teto
Copy link
Author

teto commented Mar 25, 2024

I had my plugin in append_previewers, if I move it to prepend_previewers it gets used and I see the log you mention.
It would be great if the error could be shown where the preview should have been. Right now, my preview for audio files is empty because my plugin doesn't work, it could be useful to display ERROR yazi_plugin::isolate::peek: plugin not found: test or just plugin not found: test.

I wonder if the doc at https://yazi-rs.github.io/docs/configuration/yazi/#plugin is correct:

If your append_rules contains wildcard name rules ("" or "/"), they will always take precedence over the default wildcard rules as the fallback.

shouldn't it be prepend_rules instead ?

so right now I see

  2024-03-25T11:42:03.835523Z ERROR yazi::lives::lives: runtime error: [string "yazi-plugin/src/loader.rs:59:28"]:6: attempt to call a nil value (global 'Command')
stack traceback:
        [C]: in global 'Command'
        [string "yazi-plugin/src/loader.rs:59:28"]:6: in function 'chunks.peek'
    at yazi-fm/src/lives/lives.rs:66

in my logs because of this line in my script

function M:peek()
	local child = Command("view_json")
		:args({

but yazi-plugin/preset/plugins/pdf.lua does use Command: why doesn't it exist ? is there something wrong with the nix packaging ? how is Command brought to lua ?

@sxyazi
Copy link
Owner

sxyazi commented Mar 27, 2024

Hi, the document is correct, if you use a wildcard name rule in append_previewers, such as { name = "*", run = "my-previewer" }, it will override Yazi's default wildcard previewer:

# Fallback
{ name = "*", run = "file" },

which is useful for users who need to customize fallback behavior. It's a combination of append and wildcard.

Regarding the second question, Command only exists in an asynchronous context. Did you specify sync=true for the previewer rule? Could you paste your yazi.toml contents so I can see where the issue might be?

As for displaying errors in the preview panel, this only applies to previewer plugins, and it will scatter errors - sometimes errors will appear in the preview pane (if developing a previewer), and sometimes they will appear in the log file, which can be confusing, and preview pane is also not a good place to display errors - it currently does not support line breaks, so long errors will be truncated.

@teto
Copy link
Author

teto commented Mar 28, 2024

Regarding the second question, Command only exists in an asynchronous context. Did you specify sync=true for the previewer rule? Could you paste your yazi.toml contents so I can see where the issue might be?

yes that was it.

As for displaying errors in the preview panel, this only applies to previewer plugins, and it will scatter errors - sometimes errors will appear in the preview pane (if developing a previewer), and sometimes they will appear in the log file, which can be confusing, and preview pane is also not a good place to display errors - it currently does not support line breaks, so long errors will be truncated.

I understand no problem, it was just an idea that popped in my mind when facing the issue ;)

The following is a bunch of comments partly for me to remember, that might deserve their own tickets but :

  1. I configure lua-language-server with 'ya', 'ui', 'cx', 'Command' as globals (else they pop as warnings in my editor)
  2. in this doc https://yazi-rs.github.io/docs/configuration/yazi/#open mime (String): Glob expression for matching the mime-type. Case insensitive by default, add \s to the beginning to make it sensitive.
    How is mime retreived ? is it via xdg-mime or some library ? Might be worth linking it as it can help troubleshooting issues
  3. in this doc https://yazi-rs.github.io/docs/configuration/yazi/#open Opener name corresponding to the names in the [[opener] section](https://yazi-rs.github.io/docs/configuration/yazi/#opener). There can be several entries for use, what does this mean ? are they tried in order or does yazi give a choice when opening the file ?
  4. I would like to have a verbose mode where I can see for each file what previewers are loaded, for each file which one is used and why (does it match name or use). If it hurts perf, maybe hide it behind a compilation flag ?
  5. I would also like to log from my lua plugin, print disfigure the layout of display so it's not great. Is there any log function available ?
  6. at https://yazi-rs.github.io/docs/plugins/overview I am puzzled by the sentence Each plugin is a directory with a hyphen-separated name, ending in .yazi, and containing at least the following files: LICENSE ... : does it mean yazi will ignore the plugin if it doesn't contain a LICENSE file ? I would think that only init.lua is mandatory. If the latter is the case, the sentence should be reworded.

@teto
Copy link
Author

teto commented Apr 3, 2024

gentle ping in case you forgot about this @sxyazi . The answers I am most interested at are for 4 and 5 as this is something I could leverage for my plugins.

@sxyazi sxyazi mentioned this issue Apr 5, 2024
59 tasks
@sxyazi
Copy link
Owner

sxyazi commented Apr 5, 2024

Sorry for the late reply:

  1. I think this warning is due to the lack of type definitions, unfortunately, this situation may not improve until the Yazi plugin system is stable, as there are expected to be some major changes to the API. :(
  2. Improved in yazi-rs/yazi-rs.github.io@2e55350
  3. Improved in yazi-rs/yazi-rs.github.io@2e55350 as well
  4. This sounds like the feature request "A floating window to glance at more information about this file" - I've added you to the request list.
  5. You can print debugging information to the log using ya.dbg and ya.err.
  6. They are required, and it's reserved for future use by the plugin/theme manager. They are not directly used in Yazi now, so not adding them won't affect the functionality of plugins.

@teto
Copy link
Author

teto commented Apr 5, 2024

thank you, you are the goat ;)

Copy link

github-actions bot commented May 6, 2024

I'm going to lock this issue because it has been closed for 30 days. ⏳
This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2024
@sxyazi
Copy link
Owner

sxyazi commented Nov 20, 2024

  1. I would like to have a verbose mode where I can see for each file what previewers are loaded, for each file which one is used and why (does it match name or use). If it hurts perf, maybe hide it behind a compilation flag ?

Done in #1802 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature request
Projects
None yet
2 participants