emacs-eask / cli

CLI for building, running, testing, and managing your Emacs Lisp dependencies
https://emacs-eask.github.io/
GNU General Public License v3.0
138 stars 21 forks source link

eask analyze output is sent to stderr #276

Open joshbax189 opened 1 week ago

joshbax189 commented 1 week ago

This means eask analyze does not play nicely in shell scripts.

Specifically, I want to do

eask analyze | grep "Warning"

Some commands will separate output and error per #123

> eask files
Unmatched dependency 'emacs'; add (emacs "VERSION") to package-file or consider removing it
# ...etc
/some/file/here

(Total of 1 item listed)

vs

> eask files 2>/dev/null
/some/file/here
joshbax189 commented 1 week ago

This is actually a weird emacs thing:

> emacs --batch --eval "(message \"hi\")" 1>/dev/null
hi
> emacs --batch --eval "(message \"hi\")" 2>/dev/null
# nothing

From the man page

--batch Edit in batch mode. The editor will send messages to stderr. You must use -l and -f options to specify files to execute and functions to call.

Same for the --script flag, it seems.

So is eask a wrapper for emacs --script or is it "npm for emacs"? :smiley:

jcs090218 commented 1 week ago

Hmmm… the same issue should have been solved a long while ago. See #124.

So is eask a wrapper for emacs --script or is it "npm for emacs"? 😃

Eask is the wrapper for emacs —script. Eask is not trying to hide any bugs from Emacs; therefore, the nodejs layer should forward all stdin, stdout, and stderr.

joshbax189 commented 1 week ago

Ah sorry, I didn't search hard enough, now I found https://github.com/emacs-eask/cli/issues/123 Now I see that some commands do output to stdout, just not the ones I chose to test with!

My main problem was eask analyze only outputs to stderror or nothing. This was confusing, as IMO the warnings are the expected output. I'll change the issue to specifically that.

PS: a side-effect of the above observation about emacs' --script option is that eask messages can't be separated from program messages when running eask eval, e.g.

> eask eval '(message "hello")' 
Warning (package): Package lacks a terminating comment
Warning (emacs): Unmatched dependency 'emacs'; add (emacs "VERSION") to package-file or consider removing it
Updating environment variables... done ✓
Exporting environment variables... done ✓
hello

But then, if I want to hide the diagnostic messages:

> eask eval '(message "hello")' 2>/dev/null
# no output

All of the message output of eask eval is gone too.

jcs090218 commented 1 week ago

My main problem was eask analyze only outputs to stderror or nothing. This was confusing, as IMO the warnings are the expected output. I'll change the issue to specifically that.

Yeah, the analyze command only output to the stderr stream. See

https://github.com/emacs-eask/cli/blob/a4aa34024b6e23c6b849f531faa6e1d8bd163269/lisp/core/analyze.el#L113

https://github.com/emacs-eask/cli/blob/a4aa34024b6e23c6b849f531faa6e1d8bd163269/lisp/core/analyze.el#L120

We can change to standard output instead. :)

All of the message output of eask eval is gone too.

Hmm... the eval command did forward all standard streams. 🤔

https://github.com/emacs-eask/cli/blob/a4aa34024b6e23c6b849f531faa6e1d8bd163269/cmds/core/eval.js#L56

joshbax189 commented 1 week ago

Thanks for checking!

Hmm... the eval command did forward all standard streams

Sorry this was a little off-topic from the main issue. My point was that both emacs and eask write to standard error, so when using the eask eval command there's no easy way to separate eask output from emacs output. E.g. if I want eask eval to exactly match emacs --script how would I do it?

I wonder if the --verbose option should hide eask messages, e.g. eask eval [form] -v 0 forbids Eask from printing any (own) messages.

jcs090218 commented 1 week ago

Sorry, this was a little off-topic regarding the main issue.

No worries! I might have misunderstood your question! 😅

My point was that both emacs and eask write to standard error, so when using the eask eval command there's no easy way to separate eask output from emacs output. E.g. if I want eask eval to exactly match emacs --script how would I do it?

Do you mean the Node.js layer and Emacs outputs? Right now, there is no way to separate these outputs. We will have to change the command behavior. 🤔

I wonder if the --verbose option should hide eask messages, e.g. eask eval [form] -v 0 forbids Eask from printing any (own) messages.

Eask is hybrid (Node.js + Elisp), so it has to print something, or else it would have no outputs. 🤔