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

bat silently quits, rather than reporting an error, if less is missing #2904

Open
FlashSheridan opened this issue Mar 19, 2024 · 7 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@FlashSheridan
Copy link

What steps will reproduce the bug?

  1. Install bat on a machine without less (a minimal Docker image in my case with 22.04.4 LTS (Jammy Jellyfish) x86_64, where of course bat was the first thing I wanted to install):
    sudo apt install bat fd-find…
  2. Run it:
batcat  --generate-config-file
batcat  /root/.config/bat/config

What happens?
Nothing, but the file exists:

root@kromodeor:~/Documents/Code/compiler-tester/llvm# batcat  /root/.config/bat/config
root@kromodeor:~/Documents/Code/compiler-tester/llvm# ls -l  /root/.config/bat/config
-rw-r--r-- 1 root root 1114 Mar 19 15:58 /root/.config/bat/config

What did you expect to happen instead?

Error message stating that my poor pathetic installation lacked less.

How did you install bat?

time sudo apt install bat fd-find silversearcher-ag tldr  nano

bat version and environment

batcat /root/.config/bat/config --diagnostic
bat has been built without the 'bugreport' feature. The '--diagnostic' option is not available.

batcat --version
bat 0.19.0

apt info bat
Package: bat
Version: 0.19.0-1ubuntu0.1
Built-Using: rust-ansi-colours (= 1.0.1-2), rustc (= 1.59.0+dfsg1-1~ubuntu2~22.04.1)
…
@FlashSheridan FlashSheridan added the bug Something isn't working label Mar 19, 2024
@keith-hall keith-hall added the good first issue Good for newcomers label Mar 25, 2024
@Muresan73
Copy link

I would look into this, can you assign it to me please.

@Muresan73
Copy link

In the meantime, I tried to reproduce the issue, but I could not replicate the same behavior as @FlashSheridan .
Using the ubuntu:jammy container, I verified that less is not present, and then running your command resulted in:

root@test:/# less
bash: less: command not found

root@test:/# batcat  -V                      
bat 0.19.0

root@test:/# batcat  --generate-config-file
Success! Config file written to /root/.config/bat/config

root@test:/# batcat  /root/.config/bat/config
       │ File: /root/.config/bat/config
───────┼────────────
   1   │ # This is `bat`s configuration file. Each line either contains a comment or
   2   │ # a command-line option that you want to pass to `bat` by default. You can
   3   │ # run `bat --help` to get a list of all possible configuration options.
   4   │ 
   5   │ # Specify desired highlighting theme (e.g. "TwoDark"). Run `bat --list-themes`
   6   │ # for a list of all available themes
   7   │ #--theme="TwoDark"
...

In my case, bat defaults correctly to not using a pager if less is not present.

Could it be that somehow no argument is received, causing bat to hang and wait for stdin as it normally does?

@FlashSheridan
Copy link
Author

(a minimal Docker image in my case with 22.04.4 LTS (Jammy Jellyfish) x86_64,

In the meantime, I tried to reproduce the issue, but I could not replicate the same behavior as @FlashSheridan . Using the ubuntu:jammy container, …

Hmm, there could well be something else unusual about our company’s minimal Docker image. Attached is the relevant part of the session in which I created the container and encountered the problem. We’re in the process of open-sourcing; let me know if there’s anything you can’t access, or if you need more information.

Docker cmds excerpts 2024-03-20 6-39-09 PM.txt

@Muresan73
Copy link

I used your image, tried to have different permissions for less, played around with bat config but the results were the same.

I will try to tamper the code maybe something pops up.

@FlashSheridan
Copy link
Author

I used your image, tried to have different permissions for less, played around with bat config but the results were the same.

Odd, on my container the bug reproduced when I removed less, below. Happy to run diagnostics while it’s in this state.

root@kromodeor:/# apt remove less
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  less
0 upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
After this operation, 329 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 42244 files and directories currently installed.)
Removing less (590-1ubuntu0.22.04.2) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
root@kromodeor:/# 
root@kromodeor:/# 
root@kromodeor:/# batcat  /root/.config/bat/config

This is a pretty minimal image, e.g.

root@kromodeor:/# man apt
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, including manpages, you can run the 'unminimize'
command. You will still need to ensure the 'man-db' package is installed.

@Muresan73
Copy link

I was checking the code, and bat should fall back to regular non-pager stdout if the pager initiation have any problems. I couldn't find any corner cases.
On the other hand, if the pager itself encounters any problems that is outside of bat's scope. My guess is there is maybe a misconfigured less binary or symlink on your path that outputs nothing for some reason. I created a dummy binary, and the output is piped through it.

root@46test:/# batcat  /root/.config/bat/config --pager=lesser 
Hello, world!
thread 'main' panicked at src/main.rs:3:5:
There was an issue                                                                                           

@FlashSheridan
Copy link
Author

Interesting, I get the usual silent failure with a nonexistent pager:

root@kromodeor:/# batcat  /root/.config/bat/config   --pager=SirNotAppearingInThisContainer
root@kromodeor:/# echo $?
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants