snazzer icon indicating copy to clipboard operation
snazzer copied to clipboard

Without perl-doc installed `snazzer --man` doesn't behave well

Open jamiereid opened this issue 8 years ago • 9 comments

uname -a = Linux 4.8.0-1-amd64 #1 SMP Debian 4.8.7-1 (2016-11-13) x86_64 GNU/Linux Bash version 4.4.5(1)-release

Without perl-doc installed, when running snazzer --man, the source code for snazzer is displayed. After closing (is it less that's used?) a message is presented saying that "You need to install the perl-doc package to use this program".

Expected behaviour: I believe it would be good to, if the dependency isn't there, gracefully fail to the info message instead of opening the source code.

jamiereid avatar Nov 29 '16 21:11 jamiereid

It seems like the perl-doc debian package only contains perl manpages, and no executables.

snazzer manpage display generation needs the pod2usage executable, that is bundled with perl in Debian as well. Could it be that you didn't have perl installed, and perl-doc pulled in perl as a dependency?

The code to display the manpage in snazzer essentially boils down to a simple pod2usage --verbose 3 ./snazzer.

Currently investigating how this could result in source code display instead of command not found…

florianjacob avatar Nov 30 '16 13:11 florianjacob

Ok, if I replace pod2usage with a command that doesn't exist, I get an error that that command does not exist. This is strange. So I guess you a

Questions:

  • Did you have perl installed before? (I guess so, but just to be sure)
  • Could you remove perl-doc again, and then post what's happening on a pod2usage --verbose 3 $(which snazzer)

florianjacob avatar Nov 30 '16 13:11 florianjacob

Sorry it's taken a while for me to reply @florianjacob

  • I assume I had perl installed before, I don't remember it coming down as a dependency when I installed perl-doc
  • Removing perl-doc and running pod2usage --verbose 3 ./snazzer yields the same behavior as in my initial post

jamiereid avatar Dec 06 '16 07:12 jamiereid

No worries, I now have an idea what's happening there. 😄

I found out that without perl-doc installed, /usr/bin/perldoc contains only this:

#!/bin/sh
# place-holder, diverted by perl-doc
echo You need to install the perl-doc package to use this program. >&2
exit 1

which is (very probably) the thing that's causing the error message.

I guess there's some pipe in pod2usage /usr/bin/snazzer like cat /usr/bin/snazzer | perldoc --some-options | $PAGER, which would explain the observed behaviour.

There's nothing we can do about this in our usage of pod2usage, it seems.

Calling perldoc without arguments returns 255 on Debian 7 Wheezy, 22 using the current perl version on Arch Linux. So we could probably work around this Debian packaging by introducing a check into the --man branch like:

…
perldoc
if [ $? -eq 1 ]
  printf "Calling perldoc returned 1. You're probably running Debian and are missing the perl-doc package for this function." >&2
  exit 1
fi
…

Of course this somewhat ugly and depends on the real perldoc never returning 1. @csirac2 what do you think of this?

I'm a little reluctant to add this code as a permanent workaround for what seems like a downstream packaging bug, though.

It would be interesting to hear the Debian packager's stance to this. Maybe they're not aware that pod2usage might use perldoc in this way, or at least have a better idea how one should check whether their perldoc works or not.

Note that this isn't snazzer-specific at all, you can actually reproduce this with any text file, e.g. pod2usage --verbose 3 /usr/bin/pod2usage or even pod2usage --verbose 3 /etc/os-release. Each of those will first show the file and afterwards display the error message.

@jamiereid, in case you want to help @csirac and me out some more, do you think you could open a Debian bug about pod2usage behaving like you described, and post the link here?

florianjacob avatar Dec 10 '16 20:12 florianjacob

I'm aware of the perl-doc limitation. I'm not sure we want to complicate snazzer here; perhaps this would be a problem best solved by doing proper releases with pre-compiled man pages.

I think the actionable thing here for this bug is to ensure we're failing loudly during make if man pages can't be generated properly; we should create a separate issue for packaging and/or proper tarball releases.

csirac2 avatar Dec 13 '16 08:12 csirac2

Would implementing something like:

  • if perldoc in path
    • if file -b --mime-type /usr/bin/perldoc is not text/x-shellscript
      • pod2usage -verbose 3

cover the "failing loudly during make if the man pages can't be generated properly"?

jamiereid avatar Dec 22 '16 04:12 jamiereid

AFAIK the dummy pod2usage already exits non-zero, is that the case? We just want the "build" to fail if build dependencies are missing

csirac2 avatar Dec 22 '16 05:12 csirac2

Strange thing is, at least on Debian Jessie, the pod2usage call for snazzer --help works, it's only when you attempt the pod2usage -verbose 3 call that it fails without the real perldoc installed. Without perl-doc installed /usr/bin/perldoc is a simple shell script telling you to install perl-doc

That's lead me to think the problem is more around perl-doc missing and less around pod2usage. Have I followed a red herring?

jamiereid avatar Dec 22 '16 05:12 jamiereid

@jamiereid No, you're right. :smile: I found the same and tried to express that in https://github.com/csirac2/snazzer/issues/49#issuecomment-266236004 .

pod2usage is fully functional without perl-doc installed, except in the case of -verbose 3 where manpages are generated. In that case, the dummy perldoc is still executed, but pod2usage doesn't expect perldoc to return -1 and no output, which leads to this strange behaviour. A real perldoc called without arguments returns neither 0 or 1 but something higher, so we could use this to make the check in the Makefile.

florianjacob avatar Dec 22 '16 23:12 florianjacob