What environment anad shell are task commands executed in?
I am trying to evaluate the result of a command which pipes through tee so that output of the command is logged to the STDOUT and saved in a file at the same time.
The idea is to then invoke a script that logs the outcome of the command depending on the exit code in a file.
BUT:
If there are pylint findings the exit code is 16 so a non-zero one but the end result of the pipe is 0 (due to the tee command)... Now how can I catch that in taskfiles?
If I try with
$?
it's 0
... in order to correctly catch it I must use set: [pipefail]
.
But if I use it, the task errors out and never reaches the script that logs the result (not to mention that it interrupts the whole task execution)...
Ok so I will ignore the error instead using ignore_error: true
.
Still problem though as ignore_error
is not actually ignoring anything - it is instead overriding the exit code to be 0 instead of 16. More appropriate name should have been override_error
🙂
Ok so let's use the appropriate way of handling this by utilizing ${PIPESTATUS[0]}
(${pipestatus[1]}
in zsh):
This way the execution will not fail but I will still catch that the exit code of the pylint command is non zero.
Awesome! But whatever environment or shell this is running in does not have pipe status being set at all...
In fact if you simply run set
it outputs nothing...
Soo... how can I handle that error handling mess?Solution:Jump to solution
found it!
if you put everything you want in a script and invoke the script as follows:
```shell...
1 Reply
Solution
found it!
if you put everything you want in a script and invoke the script as follows:
and then setup the task simply like this:
everything works as expected:
pipefail
and $?
work as intended without having to ignore any errors or break the execution.