kscripting / kscript

Scripting enhancements for Kotlin
MIT License
2.07k stars 124 forks source link

Add an option to suppress final error output #396

Open cgruber opened 1 year ago

cgruber commented 1 year ago

In some contexts, you don't want kscript to print a "[ERROR] Execution of scriplet failed:" with the command output, since the error information is all supplied by the script. Either adding this to --silent or providing a separate suppression option would be great. Otherwise, some scripts which are intended to fail in normal operations (i.e. CI scripts) will be extra noisy despite behaving as expected.

chardskarth commented 1 year ago

Need this as well! I'd be interested in submitting a PR @holgerbrandl if you need help on this one.

aartiPl commented 1 year ago

Should we suppress the error message completely, even in silent mode? I think it would be better to print a single line with an error message even if silent mode is enabled. To achieve that it would involve implementing a custom Exception class, which can keep a message and detailed description of the problem. Then in logger in silent mode, we can just print the message without description and stack trace.

I will be happy to apply PR if you can provide it.

cgruber commented 1 year ago

I think the point here is that there be no line at all - to leave all output to the explicit actions of the script developer's code, rather than the kscript framework. Maybe --silent isn't the right key here - maybe some other word conveys it.

I could try to whip something up, though I'm not familiar with kscript - I'm sure I could figure out where the output is generated and suppress there.

cgruber commented 1 year ago

Any action on this? I'm also willing to maybe put in some time on it, but I am swamped right now coming back from being sick, so I don't know how much value I can bring here in the immediate term. But if no one does this soon-ish, I may need to. We're using kscript increasingly in our test and ops infrastructure, and I would really like to be able to have more control over output, especially where we are purposely exiting non-zero (for posix pipe purposes) and managing output ourselves in the script.

aartiPl commented 1 year ago

@cgruber - I am concentrating on another project, which you might also be interested in, according to what you say above. The new project will allow access from scripts to many different command line tools like git, gradle, lxc, etc. From that point of view, I would prefer if anyone could implement correctly the "-s, --silent" feature in kscript. It shouldn't be difficult as the code is quite simple and, I hope, understandable. I agree with the previous comments: the feature should disable any output which comes from kscript, including e.g. information about the resolution of dependencies.

If you are able to spend some time developing this feature, feel free to branch out from the kscript_4.3 branch (which now just reflects the master branch) and implement the feature over there.

aartiPl commented 1 year ago

I even think that the -s, --silent should be the default (so in fact this option should be removed), and then if the user needs additional logging he/she needs to add option either -v, --verbose for more logs, and -d, --development for very detailed logging.

This way it will be much easier to handle scripts with shebang line:

!/usr/bin/env kscript

as the default will be silent mode.

cgruber commented 1 year ago

Can you not just handle it by passing hte flag on the shebang line?

#!/usr/bin/env kscript --silent

On Wed, 21 Jun 2023 at 22:50, Marcin Kuszczak @.***> wrote:

I even think that the -s, --silent should be the default (so in fact this option should be removed), and then if the user needs additional logging he/she needs to add option either -v, --verbose for more logs, and -d, --development for very detailed logging.

This way it will be much easier to handle scripts with shebang line:

!/usr/bin/env kscript

as the default will be silent mode.

— Reply to this email directly, view it on GitHub https://github.com/kscripting/kscript/issues/396#issuecomment-1602046235, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACQ3YWSBEHJZ33YHJFOBF3XMPMIZANCNFSM6AAAAAAVDNIDTQ . You are receiving this because you were mentioned.Message ID: @.***>

--

Christian Gruber @.*** 267-304-9053

aartiPl commented 1 year ago

I remember it is possible, but I need to remember how. That was a suggestion, so feel free to skip it, as it won't change anything in the current kscript behavior. The drawback of using --silent as a default is that we will not understand anything about why the script has failed. So maybe it is not that good idea after all :-)

chardskarth commented 10 months ago

We're you able to remember how you did it now? 😅 @aartiPl

cgruber commented 10 months ago

My recollection when trying --silent was that it didn't show anything about the compilation process, but if the script ended with anything other than exit code zero, it still showed a lot of boilerplate about the execution.

On Mon, 23 Oct 2023 at 23:24, Richard Glen Domingo @.***> wrote:

We're you able to remember how you did it now? 😅 @aartiPl https://github.com/aartiPl

— Reply to this email directly, view it on GitHub https://github.com/kscripting/kscript/issues/396#issuecomment-1776601779, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACQ3YRF346J6FCU5SGK7JDYA5NJHAVCNFSM6AAAAAAVDNIDTSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZWGYYDCNZXHE . You are receiving this because you were mentioned.Message ID: @.***>

--

Christian Gruber @.*** 267-304-9053